Using Word merging

Posted by rickw on 04-Sep-2012 10:27

Hello,

Im new to progress and i have a question about merge a Word Template with an XLSX file.

I already have the folowing code but now I want to know how I can make for each record from the XLSX file a new Word document.

Also I want to know how I can save each Word document with a file name of a record that is stored in the XLSX file.

Do I need a Temp-Table for this?

Greatz Rick


Define Variable chWordApplication   As Com-handle No-undo.
Define Variable chWordTemplate      As Com-handle No-undo.
Define Variable chMerge             As Com-handle No-undo.
Define Variable chNewDoc            As Com-handle No-undo.

Create "Word.Application" chWordApplication.


chWordApplication:ScreenUpdating = True.
chWordApplication:visible = False.
chWordApplication:displayAlerts = False.

/* Opent de template */
chWordTemplate = chWordApplication:documents:Open("h:\code\bestanden\test.docx",,Yes,False).

chMerge = chWordTemplate:MailMerge.

/* Opent de data source */
chMerge:OpenDataSource("h:\code\bestanden\test.xlsx").
chMerge:SuppressBlankLines = False.

/* Runt het samenvoegen */
chMerge:Execute.

/* Maakt het nieuwe samengevoegde document */
chNewDoc = chWordApplication:ActiveDocument.
chNewDoc:fields:update.
chWordApplication:visible = True.

Release Object chWordTemplate.
Release Object chMerge.
Release Object chNewDoc.
Release Object chWordApplication.

All Replies

Posted by jquerijero on 04-Sep-2012 13:37

Can you just chunk the resulting Word document to multiple files? I assume that the content of the document is a repeating letter just addressed to different receipient each page.

Posted by rickw on 04-Sep-2012 13:44

Every 2 pages Ill have to chunk the pages, but how can i do that?

How can I save each document with a file name from the XLSX?

Posted by jquerijero on 04-Sep-2012 13:59

I would assume that the letters are arranged in the same position in the Excel file.

Posted by rickw on 04-Sep-2012 14:18

Yes they are aranged in the same position of the excel file.

In the excel file are 7000 records.

After saving the letters I will add them to an application this section has been written.

Posted by jquerijero on 04-Sep-2012 17:14

It's been a while since I manipulated a Word document. You will need to select using the Range method and cut and paste it to a new Word Document.

If you're going to this level, you might wanna try using Microsoft.Office.Interop.Word and Microsoft.Office.Interop.Excel instead of COM automation.

Posted by rickw on 05-Sep-2012 02:08

Can i use that in openedge 10.2B ?

Posted by Admin on 05-Sep-2012 02:12

Can i use that in openedge 10.2B ?

Certainly. But officially you need to be on Service Pack 2.

http://blog.consultingwerk.de/consultingwerkblog/2010/09/progress-relaxes-usage-restrictions-of-gui-for-net-bridge-with-10-2b-service-pack/

Posted by rickw on 05-Sep-2012 02:41

im on SP2. I will search on google to find my solution or is here anyone with a solution?

Posted by rickw on 05-Sep-2012 07:42

Problem has been solved with a TempTable.

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/26/Word_5F00_TT.rar.zip:550:0]

This thread is closed