Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mail Merge width Word - enhanced trick
Message
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Miscellaneous
Thread ID:
00185458
Message ID:
00185508
Views:
27
>>Hi All!
>>
>>I faced a problem and I hope, somebody will help me. So. I want to make form letters to via OLE automation in Word.
>>A simple mail merge in Word via OLE is very easy task. But, I donnot have any idea, how to make form letters with more than one source records on it. A sample:
>>
>>Dear {{customer name}}!
>>
>>Your unpaid invoices:
>> {{invoice}}
>>
>>Sincerely ...
>>
>>I can make this type of formletter in only cases, if a costumer has only one unpaid invoice. But how to handle, when there are more than one invoice to print? I thought, that I will make some rows of fileds for invoices. But what if, there are more invoices? (It is something like the VFP report writer)
>>
>>
>>Any advice will be appreciated!!
>>
>>TIA
>>
>>BB
>
>Bela,
>
>Even for VFP reports I tend to produce a single "mammoth" cursor that contains all the required info. So in your case, I'd have the customer name appear on every line. That's for one.
>
>Then you'll have to build some sort of grid to show the data. Here is some code to get you started. It should ask you for a directory and document all the DBF's it finds there. I tried it and get an OLE error on my work machine. I'll try it from home tonight, because I'm pretty sure it worked once...
>
>José
>--------------------------
>PRIVATE lcDir, ;
> lnArchives, ;
> laFiles, ;
> lnCount, ;
> x
>
>IF ! "FOXTOOLS" $ UPPER(SET("LIBRARY"))
> SET LIBRARY TO HOME() + "FOXTOOLS" ADDITIVE
>ENDIF
>
>lcDir = GETDIR(CURDIR(), "Où sont les tables?")
>
>IF EMPTY(lcDir)
> = MESSAGEBOX ("Pas de répertoire sélectionné!")
> RETURN
>ENDIF
>
>lnArchives = ADIR(laFiles, (lcDir+"*.DBF"))
>
>oWord = CREATEOBJECT("Word.Application")
>oWord.Visible = .T.
>oWord.Documents.Add
>
>FOR lnCount = 1 TO lnArchives
> x = lnCount
> USE (lcDir + laFiles[lnCount, 1])
> DO WriteTable
>ENDFOR
>
>oWord.WindowState = 1
>
>*-- Column 1: name of field
>*-- Column 2: type
>*-- Column 3: size
>*-- Column 4: width
>*-- Column 5: description
>
>
>PROCEDURE WriteTable
> PRIVATE lnFields, ;
> laFields, ;
> lcDBF
>
> lnFields = AFIELDS[laFields]
> lcDBF = JustFname(DBF())
>
> oWord.activeDocument.Content.InsertAfter(lcDBF)
> oWord.activeDocument.Content.InsertParagraphAfter
> oWord.selection.moveDown 1
>
> oWord.activeDocument.range(oWord.activeDocument.Paragraphs(1).Range.start, ;
> oWord.activeDocument.Paragraphs(lnCount + 1).Range.end)
> oWord.selection.moveDown 1
> oWord.activeDocument.Content.tables.add(oWord.selection.range, lnFields+1, 5)
>
> *-- write the header of each table
> oWord.activeDocument.Tables(x).cell(1,1).Range.InsertAfter("Name")
> oWord.activeDocument.Tables(x).cell(1,2).Range.InsertAfter("Data Type")
> oWord.activeDocument.Tables(x).cell(1,3).Range.InsertAfter("Size")
> oWord.activeDocument.Tables(x).cell(1,4).Range.InsertAfter("Width")
> oWord.activeDocument.Tables(x).cell(1,5).Range.InsertAfter("Description")
>
> oWord.activeDocument.Tables(x).Rows(1).Select
> oWord.Selection.Font.Size = 14
> oWord.Selection.Font.Bold = .T.
>
> LOCAL lnCount
>
> FOR lnCount = 1 TO lnFields
> oWord.activeDocument.Tables(x).cell(lnCount+1, 1).Range.InsertAfter(laFields[lnCount, 1])
> oWord.activeDocument.Tables(x).cell(lnCount+1, 2).Range.InsertAfter(laFields[lnCount, 2])
> oWord.activeDocument.Tables(x).cell(lnCount+1, 3).Range.InsertAfter(laFields[lnCount, 3])
> oWord.activeDocument.Tables(x).cell(lnCount+1, 4).Range.InsertAfter(laFields[lnCount, 4])
> ENDFOR
>
> FOR lnCount = 1 TO lnFields+3
> oWord.Selection.moveDown
> ENDFOR
>
> oWord.activeDocument.Content.InsertParagraphAfter
>
>ENDPROC
>----------------------------------

Thanks Jose, I see, your code makes the datasource to the formletter. But how should the formletter itself look like?

BB
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform