Page 1 of 1

How read lines of word doc

Posted: Tue Feb 23, 2021 9:04 pm
by Romeo
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

Re: How read lines of word doc

Posted: Wed Feb 24, 2021 8:21 am
by anserkk
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: Select all

#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

Re: How read lines of word doc

Posted: Wed Feb 24, 2021 8:53 am
by Horizon
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.

Re: How read lines of word doc

Posted: Wed Feb 24, 2021 9:30 am
by MarcoBoschi
very useful 8)

Re: How read lines of word doc

Posted: Wed Feb 24, 2021 8:10 pm
by Romeo
Great the solution of "anserkk"
It works

I will use it and start my work

Many thanks

Re: How read lines of word doc

Posted: Fri Feb 26, 2021 4:36 am
by ryugarai27
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)

Re: How read lines of word doc

Posted: Thu Sep 16, 2021 11:49 am
by Romeo
Grazie to anserkk

But now i need to extract lines (or paragraphs) from a word file and write them in another files


By using the anserkk example i get only text without color, bold, formatting


Any suggestion

Grazie