FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How read lines of word doc
Posts: 340
Joined: Thu Jan 25, 2007 03:53 PM
How read lines of word doc
Posted: Tue Feb 23, 2021 09:04 PM

Hi to all

I need a little example to how to read the line (txt) of a word doc, line by line

I need it because there are some informations inside thay i have to manipulate

PS: i know how to wrinte txt in word doc, but i dont know how to read it !!
Grazie

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: How read lines of word doc
Posted: Wed Feb 24, 2021 08:21 AM
The following example reads word contents, paragraph wise. Not sure whether this is what you are looking for. Maybe you can modify the code to suit your requirement

Code (fw): Select all Collapse
#Include "Fivewin.ch"
*---------------------------*
Function Main()

    Local oWord,oDoc,cWordFileName,aData, oPara
       
    cWordFileName:="D:\Test.Doc"
    
    oWord := CreateObject("Word.Application")
    oWord:DisplayAlerts := 0
    
    oDoc := oWord:Documents:Open(cWordFileName)  //Open the word document
    aData:={}
    For Each oPara In oDoc:Paragraphs
        aAdd( aData, oPara:Range:Text )
    Next oPara
    oDoc:Close()
    oWord:Quit()
    
    xBrowser aData

Return
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM
Re: How read lines of word doc
Posted: Wed Feb 24, 2021 08:53 AM

Hi,

anserkk's solution when the Mic. Word is installed.

If it is not installed. there is a long solution.

  1. rename file extention to zip. (eg. myfile.docx to myfile.zip)
  2. unzip the zip file using hb_unzip() function.
  3. there are several xml files in unzipped directory. find the xml file that is your information is looking for. and read xml file.
Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: How read lines of word doc
Posted: Wed Feb 24, 2021 09:30 AM

very useful 8)

Marco Boschi
info@marcoboschi.it
Posts: 340
Joined: Thu Jan 25, 2007 03:53 PM
Re: How read lines of word doc
Posted: Wed Feb 24, 2021 08:10 PM

Great the solution of "anserkk"
It works

I will use it and start my work

Many thanks

Posts: 65
Joined: Fri Feb 13, 2009 12:03 PM
Re: How read lines of word doc
Posted: Fri Feb 26, 2021 04:36 AM
Hi Anser,

Great work!

Is there also a way to get the words with emphasis? For example, I want to enclose all italic words in <italic>italic word</italic> and bold words in <bold>bold word</bold>.

Many thanks,
ryu ( FWH1706 + xHB1.0 + Pelles C + VS Code)

Continue the discussion