how to detect an image inside word document?

205 views
Skip to first unread message

rodrego sandino

unread,
Mar 20, 2023, 2:49:52 PM3/20/23
to Harbour Users
Hi everybody ,is there any code to determined whether a word document has an image in it or not?

Bernard Mouille

unread,
Mar 21, 2023, 4:00:27 AM3/21/23
to Harbour Users
Hello Rodrego,
Maybe you can take some idea in the code below my signature.
Regards,
Bernard.

// Begin code.

// Parameter.
#define Word_File hb_dirbase() + "MyFileTxt.docx"
procedure Main
   local oWord
   local oDoc
   local oImgs
   local i
   oWord         := Win_OleCreateObject( "Word.Application" )
   oWord:Visible := .T.
   oDoc          := oWord:documents:open( Word_File )
   if oDoc:Content:InlineShapes:Count > 0
      oImgs := oWord:Documents:Add()
      for i := 1 To oDoc:Content:InlineShapes:Count
         oDoc:Content:InlineShapes( i ):Range:CopyAsPicture()
         oImgs:Paragraphs:Add()
         oWord:Selection:Paste()
      endfor
    endif
   oWord := NIL
   return

// End code.

J Muller

unread,
Mar 21, 2023, 7:34:38 AM3/21/23
to Harbour Users
docx files are just zipped xml-files, so you can check for the folder where word stores image-files.

they should be in the /word/media  folder inside the docx.  
inside powerpoints it is /ppt/media 
On some file-managers you can click ctrl_pgdwn to list the contents of zipped files (double-commander, total commander) and you can just descend into the directories.

So you should be able to search inside a zip for the existence of the media folder or get a file-count from it.

rodrego sandino

unread,
Mar 24, 2023, 4:22:52 PM3/24/23
to Harbour Users
thank you very much bro for your answer i had implemented your code and i got this error:
Error: Unresolved external '_HB_FUN_WIN_OLECREATEOBJECT' referenced from C:\USERS\LENOVO\APPDATA\LOCAL\TEMP\HBMK_QMY961.DIR\TESTERMODEL.OBJ

which means that  " Win_OleCreateObject"function is not define so how can i solve this problem ?
and i want to ask you something ...is this code able to determine where  is the location of the image inside the word file (where does it start ?and where does it end ?) 

Vlademiro Landim

unread,
Mar 24, 2023, 8:41:17 PM3/24/23
to Harbour Users
try : hbmk2 main.prg hbwin.hbc

rodrego sandino

unread,
Mar 25, 2023, 9:54:20 AM3/25/23
to Harbour Users
Thank you my brother ...can you give me simple direct code ?

Vlademiro Landim

unread,
Mar 25, 2023, 1:27:46 PM3/25/23
to harbou...@googlegroups.com
https://github.com/hbmshell/core/blob/main/cookbook/WinWord2/

Compile using hbwin.hbc

Hbmk2 main.prg hbwin.hbc


this example is not mine. It was posted at the beginning of the thread.



--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to a topic in the Google Groups "Harbour Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/harbour-users/A2n_pxZ5jiI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/88d27dd6-2d3f-4339-8e31-b2a6907f2fffn%40googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages