Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word Manipulation Through VFP
Message
De
03/09/1998 05:16:55
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
03/09/1998 01:01:39
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00124749
Message ID:
00132682
Vues:
91
>>To speed up when there is no memo field need and not very large table you may also try not using ODBC but pasting :
>
>
>>_VFP.datatoclip(alias(),reccount(),3) && Copy VFP table to clipboard
>>oWord.editpaste  && Paste to word
>>*No memo (memo is pasted like in Browse memo-Memo)
Cetin
>
>
>Hello, Cetin!
>
>Picking up an old (but good) thread here. In my app the user writes one form letter at a time for each resort reservation that is completed. I want to make a lot of data fields available to the user who creates these form letters but there would be only one row in the table at the time of the merge. It seems like this paste method would be appropriate to my situation.
>
>Some questions: Can I define a datasource with named fields which makes it easy for the user to pick fields and insert them into a form letter?
Yes, you can play with headers in word or before sending to word. I did it in word in the following example.

>
>Does this paste method create what Paul Witt calls a "word table"?
Yes, it's a word table. Also I read some of messages but I didn't get into that discussion for some personal reasons (or you would think me as a VFP fanatic - uhh not wrong :) totally).

>
>I couldn't find an "editpaste" method for Word in the object browser. Is that the correct name?
Yes, but not word97 (VBA) name. It's word.basic as in the following example. All have VBA counterparts but I prefer word.basic because it's supported both in Word95 and Word97 (not all commands work in Word97 as they should but all those in example work).

>
>I tried _VFP.DataToClip. It worked and I pasted the results by hand into a word document. Would this document than become a datasource for the form letter document?
Yes, but not directly. First an active document creates header source, edits it (that is where we paste), then main doc is activated. User can now type his/her text and insert any field from "word table" pasted using the "insert merge field" tab (when code run notice mail merge toolbar activated).

>
>I'm getting help with my problem in a current thread #132599.
>
>Thanks for any help.
>
>Peter Robinson
Peter,
Just one row at a time and no memo this is the fastest as I know :
**************************************************
* Start of code
**************************************************
USE (home()+"samples\data\customer")
GO 18
_VFP.datatoclip(alias(),1,3) && Copy VFP table to clipboard - Just recno()=18
LOCAL ix
LOCAL array aNewFieldNames[fcount()] && Will change some headers later
FOR ix=1 to fcount()
  aNewFieldNames[ix] = field(ix)  
* open database (home()+"samples\data\testdata")
* dbgetprop(alias()+"."+field(ix),"Field","Caption") is a shorcut
* if captions already have your new field titles
ENDFOR
aNewFieldNames[1] = "Customer Id"
aNewFieldNames[2] = "Company Name"
aNewFieldNames[3] = "Pls Contact To"
USE
PUBLIC oWordDocument

*** set the LOCALEID to English
nlLocaleId=sys(3004)	&& Save local id
=sys(3006,1033)		&& We will be sending instructions in English

WAIT window nowait "Creating Word Document..."     && Inform user
oWordDocument=createobject("word.basic")	&& Create word object

WITH oWordDocument
  .appshow			&& Show word app
  .filenewdefault   && New file, default template - this is our main doc
  .MailMergeCreateDataSource("c:\temp\xmergedoc")  && Create datasource
  .MailMergeEditDataSource	&& Edit data source
  .editselectall	&& Select entire doc - has default fields now
  .editpaste  		&& Clipboard data pasted to word - paste over
  .editfind(" ","",0,0,0,0,0,0,,1,,1) && Remove spaces - otherwise header fail
  .editselectall	&& Select entire doc
  .texttotable(1)	&& Convert text to table - tabs (1) (Word table)
  .editgoto("\Table")	&& Go to predefined bookmark \Table - Start of table
  .nextcell
  .prevcell		&& .nextcell .prevcell to select first cell
  FOR ix=1 to alen(aNewFieldNames)
    .insert(aNewFieldNames[ix])  && Set new headers - user can understand better
    .nextcell           && Go next cell
  ENDFOR
  .tabledeletecolumn  && Delete extra column
  .MailMergeEditMainDocument	&& Activate the main document
ENDWITH

**** Set the LocaleId to the previous value
=sys(3006,val(nlLocaleId))

**************************************************
* End of code
**************************************************
I think this code already has the answers and I dispersed them between your questions. While ODBC seem to be slow it has an option to link to source. In fact I think what is so slow is not ODBC nor VFP but word itself. And as Barbara pointed out word could directly use a DBF too. I wrote mailmerge class preserving OOP and in the name of OOP and ODBC support didn't do it with old indian trick (export to ie:Excel type file or delimited with tab, in word insert that file-faster than ODBC).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform