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!

How to transfer a MS-Word text into a VFP-table 4

Status
Not open for further replies.

german12

Programmer
Nov 12, 2001
563
0
16
DE
I added a text in MS Word and a table structure afterwards.

I am attaching a small example-file
which looks like this

Auszug_fyr3kl.jpg


My question:
How can I make it a VFP file?
I know to create a structure for the VFP-File before - that is no problem.
If I understand it correctly, there are no delimiters in this case in the WORD-file
The Word file is very long - what is the most convenient way to turn this into a VFP file?

Thank you
Klaus

Peace worldwide - it starts here...
 
 https://files.engineering.com/getfile.aspx?folder=372e3977-1a8c-4334-b89b-d11cdfb06609&file=Sample.docx
Klaus,

As always with this kind of question, we need to know whether this will be one-off requirement (that is, something that you will do interactively), or a regualr task that you want to automate.

If the former, I suggest the following:

1. In Word, select the table.

2. Choose "Convert to text". (In my version of Word, this is under Table Tools / Layout / Data, but that might vary with different versions). Then choose "Tab delimited".

3. Save the resulting tab-delimited data in a text file.

4. In VFP, open and select the target table (DBF file or cursor), and use APPEND FROM ... DELIMITED WITH TAB to import the data.

If you need to automate the process, it should be possible to perform steps 1 - 3 above using Word Automation.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
thank you for your quick advise.
It is not necessary (at the moment) to automate the process - (perhaps later)

I had done what you wrote (and I even did it before).
The transfer works - however the result does not yet satisfy me.
As to be seen below, I receive the 4-column table in WORD now as all in one column (header = "Lieferant". in the vfp-file.

However - What I wanted is to be filled this:
Lieferant .. Gegenstand Datum Preis
Beel ...... .... .Gardinen.......... 5.3.14..... 408
Boesner ....... Malmateria .. 23.5.14...... 117

..and so on.

so the view should look like it was in WORD
but I received this:

Senkrecht_2023-06-19_115835_awnu2x.jpg


Regards
Klaus




Peace worldwide - it starts here...
 
Seems you're doing different than Mike suggested.

Append from <<filename>> DELIMITED WITH TAB works for data separated with tabs. If you don't choose tabs when converting the table to text, that APPEND won't work. If you convert separated by comma you would need another APPEND.

Are you even getting text rows from the "convert to text" feature of Word tables? Because your result suggests Word exports every cell into its own row, that can't work, of course.

Chriss
 
Klaus,

I agree with Chirs. It looks like either (i) you chose something other than "with tabs" when converting the table to text; or (ii) you used a different DELIMITED clause in the APPEND FROM.

I have just converted the table in your sample Word document. This is what I get:

klaus_zy9niw.jpg


Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike and Chriss

My MS Word program is no longer young. Version Office 2013.
So I may not be able to do a proper conversion from
Word format in a *.txt format.
I did not find what Mike wrote:This is the layout of my WORD program: (at the end a better photo is available)

Wordscreen1_wckrfg.jpg
URL]
URL]
URL]


With that I can save a WORD document as "Nur Text" (=text only) and that is what I did.
When I did this a new menu started where I could mark line break ("Zeilenumbrüche" in german) or not.
The result is either a vertical list or just the text as you can see below.

What ever I use to get these infos into a .dbf - only one column is filled.
But as the 1st. photo is not sharp enough - this is perhaps better:

wordscreen6_yg5a3b.jpg


Table tools layout - what or where could it be here?
Klaus






Peace worldwide - it starts here...
 
Klaus,

This has got nothing to do with your Word version. I've done this sort of thing with versions of Word much older than 2013. The layout of the menus might have changed, but the operation has not.

I suggest that, instead of saving the Word document as a TXT file, you copy and paste the relevant text from the Word document into, say, Notepad (or the VFP MODIFY FILE window) and save it from there.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Klaus,

Mike didn't suggest to save the whole document as a txt file, but use a tool for tables that would save table rows as text rows, tab delimited.

You might also make the best of what you have and create one reocrd from 4 records of the single column you got out of the Word, but I guess at times a cell contains two or more words that will break. No, there must be something available in the menu under tables or when you right click on a table cell or the table grid lines.

Chriss
 
Mike & Chriss
Heureka!
I copied the content of the Word file to Notes++ and from there I got the data via "delimited with tab" with APPEND like this
into the VFP file as I wanted it.
I just had to change some umlauts (eg Österreich to Oesterreich) - that is fast in Notes++ and now the VFP file is usable for me too.

I don't care why it didn't work directly with Word.
I am glad that it was possible thanks to your help.

Great! You are remarkable good!

Klaus

Result now:
Screenshot_2023-06-19_211713_hbmlss.jpg

I can see, where our money has gone to [blush]
Best investment were the e-bikes....

Peace worldwide - it starts here...
 
Hi Klaus,

In addition to what Mike and Chris suggested and if you have EXCEL

1. Select the table in your Word document
2. Copy & Paste to an empty Excel sheet
3. save as XLS and append from ... TYPE XLS

hth

MarK
 
Mike, I know ...your bike ist non-electric -you are too young for an E-Bike.I also had a normal Bike from 1950-2021...but the distance has increased now although I am older...Not bad ...

Peace worldwide - it starts here...
 
I had an e-bike, needed money and my father (over 80 yo) did me a favor and bought it from me overpriced.
End of the story, he sold it and got a normal one, as he couldn't adapt to the fast starts.

And I read that's an issue in general. Meaning e-bikes have a maximum age rather than a minimum age - when your reactions become too slow.

Chriss
 
A maximum age range for e-bikes? Now that's an interesting theory.

I was seriously considering getting an e-bike in 2020. But then came the pandemic and the lockdown. For most of that summer, we were only allowed out of the house for exercise once per day. I figured - rightly or wrongly - that I simply wouldn't get enough exercise on a bike that was power-assisted, so I stayed with my normal machine. I made a point of pushing my way up to 8 - 12 km per day, every day. And it really worked. By the end of the lockdown, I was fitter than I had been for years.

But that was then and this is now. I hadn't thought any more of going electric. But then I saw Chris's post, above. So maybe I should take the plunge before it's too late.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Translated: "Hey Sherpa, I need new akkus!"

Sherpa_Screenshot_2023-06-20_211529_cxat3v.jpg
Sherpa_Screenshot_2023-06-20_211529_cxat3v.jpg


Peace worldwide - it starts here...
 
@mjcmksr: Never use TYPE XLS. That's Excel 2.0 format and, among other things, it mangles dates badly. Always use XL5 or, on the APPEND side, XL8.

Tamar
 
Tamar and Mark,
thank you very much for your hint.
I tried it immediately - and saw that this method has an additional advantage in comparison with copy the contents of WORD into a *.txt-file.

When Excel receives that data it automatically "knows" if a column contents e.g. numbers or dates.
In the Word file that I wanted to transfer to VFP at the end, there were also 2 columns with the date and amount - and in VFP, therefore, only columns with the file structure date and integer were used in the file structure, so that you can also start with their content, for example for min/max calculations or date calculations.

This is of course not possible (or perhaps) if you want to import everything from a pure text file. (have not tested it)

Klaus


Peace worldwide - it starts here...
 
Klaus, it's not true you can only import text and integers from txt files. It all just depends on what the import table has as field types and whether the text can be converted implicitly into these field types.

If you write out a date as text you can read it into a date field, too. So the only requirement is that the text format is the same as VFP uses right now.
Code:
strtofile(Transform(Date()),"test.txt")

Create Cursor crsDate (dDate D)
Append From test.txt type delimited
? FileToStr("test.txt"), crsDate.dDate, crsDate.dDate+1

The output shows that the text file stores the date as text just as printing the date is turned into text and the third value crsDate.dDate+1 just shows the crsDate.dDate value is really a date and adding 1 to it adds 1 to the day.

And don't praise copy&paste to excel too much. If you paste ingeger numbers into an Excel spreadsheet that by chance correspond to integer representation of dates, Excel will take them as dates, even though dates were not meant. The only thing is Excel will do more best data type fit checks than VFP, it's not perfect though, not perfect at all.

If you don't start a table in Word but start with an Excel spreadsheet, that's a different story. And it would have been more appropriate for data as Excel also gives you easy options as summing. You could also embed an Excel spreadsheet in Word, but that would be the worst of both worlds.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top