R
rab
Guest
Hello blichal, My colleague Hinko is on holiday but I got it working. See source code below. The goal is to create simple letters. We need it in a few months or so but one of these days we need to confirm with our prospect that we can support OpenOffice. There is one problem. If the datasource connects to a text file (e.g. CSV), the encoding should be ANSI and not UTF-8 otherwise OpenOffice does not detect the first column. /* oo-mailmerge.p * Perform mailmerge in OpenOffice. * The source document already contains the data source 'test'. * Versions: * OpenEdge 11.3.2 (32-bits) * OpenOffice 4.1.0 * OS: Windows 7 Ultimate (32-bits) */ define variable sourcedoc as character no-undo initial 'C:/Temp/test-basis.odt'. define variable outputdir as character no-undo initial 'C:/Temp/'. define variable outputfile as character no-undo initial 'MERGED'. define variable datasource as character no-undo initial 'test'. define variable tablename as character no-undo initial 'test'. define variable hOO_application as com-handle no-undo. define variable hOO_mailmerge as com-handle no-undo. define variable Args as raw no-undo. session:appl-alert-box = true. /* Start OpenOffice application or get handle to running application. */ message 'Start OpenOffice'. create "com.sun.star.ServiceManager" hOO_application. /* Create mailmerge service. */ hOO_mailmerge = hOO_application:createinstance("com.sun.star.text.MailMerge"). /* Set mailmerge properties. * http://www.openoffice.org/api/docs/common/ref/com/sun/star/text/MailMerge.html */ message 'Set mailmerge properties'. assign hOO_mailmerge
ocumentURL = 'file:///' + sourcedoc /* source document (forward slashed only) */ hOO_mailmerge
ataSourceName = datasource /* name of data source (included in source document) */ hOO_mailmerge:CommandType = 0 /* 0 = table name, 1 = query name, 3 = SQL command */ hOO_mailmerge:Command = tablename /* name of table in data source */ hOO_mailmerge:OutputType = 2 /* 1 = printer, 2 = file, 3 = email */ hOO_mailmerge:OutputUrl = 'file:///' + outputdir /* output directory (forward slashes only) */ /* There are 2 ways to generate output: one single file or multiple individual files */ /* 1. Output to a single file */ hOO_mailmerge:FileNameFromColumn = false /* explicitly set output file name */ hOO_mailmerge:FileNamePrefix = outputfile /* output file name (excl. extension) */ hOO_mailmerge:SaveAsSingleFile = true /* save as single file */ /* 2. Output to multiple individual files hOO_mailmerge:FileNameFromColumn = true /* get file name from data source column */ hOO_mailmerge:FileNamePrefix = 'column1' /* name of data source column */ hOO_mailmerge:SaveAsSingleFile = false /* save as multiple files */ */ . /* Execute mailmerge. * The execute method takes a sequence (array) of com.sun.star.beans.NamedValue objects. * It is not clear how to create such a sequence in ABL, but fortunately this not required. * Instead, we feed an empty object of the RAW datatype to the execute method. * This causes the mailmerge service to use the default properties we set above. */ message 'Execute'. hOO_mailmerge:execute(Args). /* Dispose mailmerge service */ message 'Dispose'. hOO_mailmerge:dispose(). release object hOO_mailmerge no-error. release object hOO_application no-error. Do you have more information on direct manipulation/creation of the OpenOffice ODT ZIP files? We are doing something similar with DOCX/XSLX files but we are getting complaints from some our users, so the Docxfactory seems to be the better solution. Thank you for that.
Continue reading...
Continue reading...