Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word - Automatically merge data and show merged result
Message
De
22/02/2009 17:20:08
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00801933
Message ID:
01383365
Vues:
72
>Hi,
>
>I've been reading your various posts about Word automation and I've come to the conclusion that most are problematic. You said that the most secure method would be to create a table within a document and use that as the data source. Would you be kind enough to show me the code necessary to create this table and use it as far as Word automation is concerned?
>
>Thanks in advance for any assistance.
>
>Chaim

Chaim,
Sorry but your question is not clear. I have posted many word automation code and I don't know which one are you referring to and to do what?
PS: Noticed the title and this was a followup to an existing post about mail merge. Ok then the easy way is to use a simple tab delimited text file as the datasource.
Select * From (_samples+'data\customer') Where country='USA' Into Cursor mergethese
MergeIt('mergethese')

Function MergeIt
Lparameters  tcAlias, tcTemplateDoc
Local nLocaleID,lcTemp,lcHeader
Local loWord,llToPrinter,lcSourceDoc

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

* Prepare source
Select (m.tcAlias)
lcTemp = Sys(2015)+'.tmp'
Copy To (lcTemp) Type Delimited With "" With Tab
AFIELDS(laFields)
lcHeader = ''
For ix = 1 To Fcount()
    lcHeader = lcHeader + ;
        Iif(Empty(m.lcHeader),'',Chr(9)) + ;
        Field(m.ix)
Endfor
lcSourceDoc = Sys(5)+Curdir()+'MergeSource.txt'
Strtofile(m.lcHeader+Chr(13)+Chr(10)+Filetostr(m.lcTemp),m.lcSourceDoc)
Erase (m.lcTemp)

loWord=Createobject("word.application")	&& Create word object
With loWord
    If Empty(m.tcTemplateDoc) && No template
        .documents.Add()  && New file
    Else
        .documents.Add(m.lcTemplateDoc)  && Open a template
    Endif
    With .Activedocument.Mailmerge
        .OpenDataSource(m.lcSourceDoc) && Set file as data source for mailmerge
        .EditMainDocument	&& Activate the main document

* Just to sample programmatic writing
        .Application.Selection.TypeText("Company : ")
        .Fields.Add(.Application.Selection.Range,'company')
        .Application.Selection.TypeText(Chr(13)+"Dear contact : ")
        .Fields.Add(.Application.Selection.Range,'contact')
        .Application.Selection.TypeText(Chr(13)+"Blah blah ...."+Chr(13))
* Just to sample programmatic writing

    Endwith
    .Visible = .T.  && Show word app
    .Activate  && Make it the active foreground app
Endwith

**** Set the LocaleId to the previous value
=Sys(3006,Val(nlLocaleId))
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