Purpose Generate a Word document with multiple parts We want to create a Word document which consists of multiple parts. If the number of parts depends on the data read (e.g. customers, projects,...), we cannot work with a single rtf template. An alternative to the solution described here is to generate the document via Word automation, but the required coding will then become more complicated. |
Solution
1. Placeholder file "&[rtfinclude.###].rtf&q"
Start with a document that contains all fixed parts such as a header, footer, title, page count,... Then insert a table with one row, one column and add a link to the placeholder file in the table cell. This is done as follows:
Click on Insert -> Object -> Text from file. Then select the placeholder file and choose "Insert as Link":
The master template now looks as follows:
Save the file as "mastertemplate.rtf".
3. Sales office file Result ............................................................. .......................................................................................
|
InputScript We read the customer orders directly from the database tables VBAK and KNA1 via the function /GUIXT/dbselect. // clear variablesClear V[rtf.*] Clear V[rtfinclude.*] // read orders // fill rtf variables Set V[k] 1 // returned valueSet V[n] 1 // table row Set V[m] 1 // sales office label next_value// customer name CopyText fromText="r" toString="rtf.cp.&V[n]" line=&V[k] Set V[k] &V[k] + 1 // city CopyText fromText="r" toString="rtf.cc.&V[n]" line=&V[k] Set V[k] &V[k] + 1 // order number CopyText fromText="r" toString="rtf.on.&V[n]" line=&V[k] Set V[k] &V[k] + 1 // order date CopyText fromText="r" toString="rtf.od.&V[n]" line=&V[k] Set V[k] &V[k] + 1 // order value CopyText fromText="r" toString="rtf.ov.&V[n]" line=&V[k] Set V[rtf.ov.&V[n]] "&V[rtf.ov.&V[n]]" + 0 _ decimals=0 groupSeparator=" " Set V[k] &V[k] + 1 // sales office if
V[rtf.office]
and
not
V[rtf.office=&V[office]] endif // current sales officeSet V[rtf.office] "&V[office]" Set V[n] &V[n] + 1 goto next_value endif // generate last office CopyText fromTemplate="C:\temp\salesoffice.rtf" toText="temp" Set V[rtfinclude.&V[m]] "sales.&V[rtf.office]" CopyText fromText="temp" toFile="C:\temp\sales.&V[rtf.office].rtf" endif // generate final document using the master template // call up wordStart "C:\temp\sales.doc" Return Components InputAssistant |