Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a Word Document

Status
Not open for further replies.

martin250

Programmer
Feb 26, 2002
11
0
0
GB
Hi,

I'm hoping somebody can help me. I would like to read and get data from a Word Document and store it in a variable.
I've tried the code below but this only seems to work with a standard TXT file, when tried with a DOC file it returns weird characters.

STORE FOPEN(m.location) TO file_handle
STORE FSEEK(file_handle, 1, 2) TO lcrow
STORE FSEEK(file_handle, 0) TO ifp_top
lcLetter = FGETS(file_handle, lcrow)

I was wondering whether it was possible to do. Any help would be much appreciated.
Thanks in Advance.

Mart
 
Reading a word document also gives you the word-fileheader which contains all kind of codes (binairy) that cannot be on display.

Reading word documents this way will not work.
If you have foxpro for windows you could try the DDE possibilities of foxpro for windows.

Rob.
 
Is using DDE the only way to go about doing this?
I've also tried using an APPEND FROM, but I don't think you can do this either.
If DDE is the only way to do this can anyone help or point me in the right direction for some information about it as I'm not to sure how to use DDE. Once again any help would be much appreciated.

Mart
 
I've looked into DDE abit further, does anybody know if its possible to return all the text from a document.
I've tried using
ichannel = DDEINITIATE("WinWord", "System")
lcDocument = DDERequest(ichannel, 'c:\\test.doc')
with no luck.

I've found that, lcDocument = DDERequest(ichannel, 'Topics') returns some interesting information and that you can return cell values from excel, but I've yet to find anything about returning Documents from Word.
 
I have had a limited amount of success with this:
RENAME name.DOC TO name.TXT
STORE FOPEN('name.TXT',12) TO file_handle
STORE FSEEK(file_handle, 1, 2) TO lcrow
STORE FSEEK(file_handle, 0) TO ifp_top
lcLetter = FREAD(file_handle, lcrow)
t_string = ""
FOR t_loop = 1 TO LEN(LCLETTER)
IF ISALPHA(SUBSTR(LCLETTER,t_loop,1)) or ISDIGIT(SUBSTR(LCLETTER,t_loop,1))
t_string = t_string + SUBSTR(LCLETTER,t_loop,1)
ENDIF
ENDFOR
=fclose(file_handle)
? t_string

You can now manipluate t_string at your leisure. It's probably better to copy to rather than rename.
I had to use FREAD as FGETS gave me an internal consistency error!

Good luck!
[thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top