×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Import from WORD into a .dbf-file
4

Import from WORD into a .dbf-file

Import from WORD into a .dbf-file

(OP)
I have a very long list of purchased items in a Word document (Office 2013) in a tabular form or matrix as shown below.
4 columns: supplier, item, date of purchase, price


What is the easiest way to import this list into a VFP 9 file?

Thanks
Klaus

Peace worldwide - it starts here...

RE: Import from WORD into a .dbf-file

Hm. copy& paste into Excel and then go from there into VFP?

There is _vfp.DataToClip, but you need _vfp.ClipToData, which doesn't exist.
But you could oerhaps also use _cliptext to get the data only.
Whether dircetly using ALINES() on _cliptext or by pasting into notepad and saving as tab delimited values file.


Chriss

RE: Import from WORD into a .dbf-file

Actually, I don't think you need to go through Excel. If you copy the table directly from Word, you get tab-delimited text. So you could do something like this:

CODE -->

STRTOFILE(_cliptext, "junk.txt")
CREATE CURSOR Purchases (Supplier (C(12), Item  C(15), Date D, Price I )
APPEND FROM junk.txt DELIMITED WITH TAB 

Obviously you will adjust the field names, data types and widths to suit your needs.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Import from WORD into a .dbf-file

Yes, that was also one of my thoughts, but you know I also showed how easy you get an array from an excel range.

Yes, you can use STRTOFILE() instead of manually pasting into notepad, but even this low tech editor notepad is capable to store UTF-8, while VFP only extracts ANSI text.
Not a big problem, as ANSI also includes umlauts and more, but just a thought to maybe consider. In the end UTF-8 will also be a VFP problem if you don't use controls able to display UTF-8, like thw webbrowser control as perhaps simplest example. So the advantage is just a very slim margin when you need UTF8 capability you also need something more than VFP native controls.

Chriss

RE: Import from WORD into a .dbf-file

(OP)
Thank you Mike and Chris.
The easiest way to solve the problem for me is with STRTOFILE (),
but I am also grateful for the reference to UTF-8, and eventual ones
related problems.

Since the WORD file should also be maintained, I only have one additional question about _cliptext:

If the VFP program is to run 100% automatically,
then it would be nice if copying the word file as well
into the memory without manual intervention.

The Word file is called "Invoices.doc"

Is that possible with a VFP command - that would be a command that occurs before STRTOFILE (_cliptext, "junk.txt") can be executed?

Klaus

Peace worldwide - it starts here...

RE: Import from WORD into a .dbf-file

I would automate Word. If you only have one table object in it, it will be oWord.ActiveDocument.Tables[1], no matter where exactly.

CODE

Local loWord
loWord = CreateObject("Word.Application")
loWord.Documents.Load('...')
loWord.Activedocument.Tables[1].Range.Select()
loWord.Selection.Copy() 

Chriss

PS: even shorter without a selection:

CODE

Local loWord
loWord = CreateObject("Word.Application")
loWord.Documents.Load('...')
loWord.Activedocument.Tables[1].Range.Copy() 

RE: Import from WORD into a .dbf-file

(OP)
Hi Chriss,
thanks for your code - however I got the following OLE error code 0x 80020006 when I try

loWord.Documents.Load('RECHNUNGEN.doc') *This is my word-file in the same folder as the prg is.
See photo below.

What does that mean, or - what did I do wrong?

Thanks
Klaus


Peace worldwide - it starts here...

RE: Import from WORD into a .dbf-file

Pass in the whole fie name. Word is not in VFPs default directory. It's not the same process and even if it would be, it's not VFP.

Chriss

RE: Import from WORD into a .dbf-file

(OP)
I passed in the whole file name:
loWord.Documents.Load("c:\entw\produkt\wordholen\rechnungen.doc")

but that leads to the same error.

Peace worldwide - it starts here...

RE: Import from WORD into a .dbf-file

Okay, that's because the method is Open, not Load, sorry.

Chriss

RE: Import from WORD into a .dbf-file

(OP)
Hi Chriss,
The transfer of a WORD file to a VFP file now works fine here.
It would never have occurred to me that "Open" and "Load" are a difference when accessing a WORD file.
There is no difference between the two terms in German usage.
If someone says: "I have loaded or opened a program" then it has the same meaning here.

Where can I learn more about WORD/Excel automation?

Best regards
Klaus

Peace worldwide - it starts here...

RE: Import from WORD into a .dbf-file

Quote:

Where can I learn more about WORD/Excel automation?

Klaus, I usually recommend Tamar's conference papers as a good place to start. Go here and look for titles relating to "Automation", "Office", "Word", "Excel", etc.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Import from WORD into a .dbf-file

If the file is a docx file type, then it is really a collection of XML files contained in zip file (the zip extension is renamed to docx). You could then directly access the xml file to retrieve the table entries. This might take a bit of work, but you could create an example file and then determine the segments that are needed to be extracted. You can use an xml parser or use STREXTRACT function to extract the segments. Then you are not dependent on having Word installed if some are using alternative office applications such as OpenOffice.

RE: Import from WORD into a .dbf-file

Also, declaring a variable as a type has usually no big effect, a LOCAL var still initializes to .F. no matter if you define it as Strin, as Integer or whatever.

But when you declare a variable as Word.Application, for example, you get intellisense showing you the object PEMs. You still have to set the variable to CREATEOBJECT(OLEclassname), but VFP assumes you'll do:



So once you initialize loWord as you stated in the LOCAL declaration you an use what Intellisense offers:

There I could have seen my mistake.

Chriss

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close