How read lines of word doc

Post Reply
Romeo
Posts: 328
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

How read lines of word doc

Post 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
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How read lines of word doc

Post 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
Horizon
Posts: 997
Joined: Fri May 23, 2008 1:33 pm

Re: How read lines of word doc

Post 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.
Last edited by Horizon on Wed Feb 24, 2021 9:39 am, edited 1 time in total.
Regards,

Hakan ONEMLI

Harbour & VS 2019 & FWH 20.12
User avatar
MarcoBoschi
Posts: 925
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

Re: How read lines of word doc

Post by MarcoBoschi »

very useful 8)
Marco Boschi
info@marcoboschi.it
Romeo
Posts: 328
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: How read lines of word doc

Post by Romeo »

Great the solution of "anserkk"
It works

I will use it and start my work

Many thanks
User avatar
ryugarai27
Posts: 65
Joined: Fri Feb 13, 2009 12:03 pm
Location: Manila, Philippines
Contact:

Re: How read lines of word doc

Post 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)
Romeo
Posts: 328
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: How read lines of word doc

Post 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
Post Reply