How read lines of word doc

How read lines of word doc

Postby Romeo » Tue Feb 23, 2021 9: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
Romeo
 
Posts: 340
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: How read lines of word doc

Postby anserkk » Wed Feb 24, 2021 8: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: Select all  Expand view
#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
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How read lines of word doc

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

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: How read lines of word doc

Postby MarcoBoschi » Wed Feb 24, 2021 9:30 am

very useful 8)
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: How read lines of word doc

Postby Romeo » Wed Feb 24, 2021 8:10 pm

Great the solution of "anserkk"
It works

I will use it and start my work

Many thanks
Romeo
 
Posts: 340
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: How read lines of word doc

Postby ryugarai27 » Fri Feb 26, 2021 4: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)
User avatar
ryugarai27
 
Posts: 65
Joined: Fri Feb 13, 2009 12:03 pm
Location: Manila, Philippines


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 62 guests