frank10 Posted May 30, 2024 Posted May 30, 2024 I have a .docx that has some wrapped images in it. If I use "^g" into search, it does not find them (I think because they are not inline pictures). If I use the Go-To with Graphic, it correctly detects them. How can I find them with Word UDF? I attach a docx example: I want to detect that recipe 2 has not a picture near the title. I used this to detect the titles with style Header 3 : #include <Array.au3> #include <String.au3> #include <Word.au3> global $oDoc = _Word_DocOpen($oWord, "filename.docx") global $oRangeFound = _Word_DocFind($oDoc," ", Default, Default) While 1 $oRangeFound = _Word_DocFindEX($oDoc, Default, Default, $oRangeFound, Default, Default, Default, Default, Default, Default, "Heading 3") ;.... wend testQR.docx
argumentum Posted May 30, 2024 Posted May 30, 2024 The way I do it is to rename .docx to .zip . There you'll find the 2 QR code .png files. ( word\media\image1.png ) Not a standard way to go about it but, if it works Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
frank10 Posted May 31, 2024 Author Posted May 31, 2024 Thank you for the workaround. But it's not that easy to detect which picture belongs to which title... they are named generically "ImageXX.png" without reference to the title. I don't need to extract the QR png, I need to find out which title hasn't a picture (to add a QR with a script) Of course I have a lot of them, the file attached is a tiny example...
Nine Posted May 31, 2024 Posted May 31, 2024 Maybe using the $oDoc.Shapes object would give a collection of pictures. You can then manipulate each picture individually. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
frank10 Posted May 31, 2024 Author Posted May 31, 2024 Thank you Nine. That's an improvement! I got every QR and I can see which title there is on the paragraph near to the shape with: local $par = $oShape.Anchor.Paragraphs(1).Range.Text This way I could make an array with all the titles with QR. Then I should make another loop, searching all titles and searching in the previous array to see if there is a QR. But I would like to get the inverse., much linear..: Having a range with the title, I would like to get the shape near it, if any... How to get a shape in a range instead of all shapes in doc?
Solution Nine Posted June 3, 2024 Solution Posted June 3, 2024 (edited) I suppose you could get the title range, then use ShapeRange(1) to get QR within that range (untested). You will need to intercept the COM error if there is no QR within that range. If that does not work, post the code you got (based on the docx you provided), so we don't have to start from scratch... ps. I finally was curious about it, so here the code I used : #include <Word.au3> Local $oError = ObjEvent("AutoIt.Error", Error) Local $oWord = _Word_Create() Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\testQR.docx") For $oPar In $oDoc.paragraphs With $oPar If .style.NameLocal = "Titre 3" Then ; <<<<<<<<<< change to your language .range.ShapeRange(1) If @error Then ConsoleWrite(StringStripWS(.range.text, 3) & " does not have a QR" & @CRLF) EndIf EndWith Next Func Error($oError) EndFunc ;==>ErrFunc Edited June 3, 2024 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now