I want to do a mail merge with a resultset.
- document with fields from a datasource
- datasource is not registered
- use a ods with the same table name as the original datasource
With use of a connection with the service com.sun.star.sdbc.DriverManager I can get a resultset from a sql statement.
The resultset (oResult in code below) does hold the values.
OK.
Now do the mail merge with the service "com.sun.star.text.MailMerge" ...
The code below show what I have.
- It produces two documents (this is OK for the two record sets).
- But they are empty with CommandType = 2
- And OOo Crashes on oMailMerge.axecute(Array()) with CommandType = 0 (which I expect to be the proper one)
Code: Select all
oMailMerge = CreateUnoService("com.sun.star.text.MailMerge")
oMailMerge.DocumentURL = <sDocumentName>
oMailMerge.DataSourceName = <sDataSourceName>
oMailMerge.ResultSet = oResult
' choosing the next, will crash OOo
' oMailMerge.CommandType = 0 ' 0 = table, 1 = query, 2 = SQL-statement
' oMailMerge.Command = <sDataSourceTableName>
' choosing the next, gives no data in the document
oMailMerge.CommandType = 2 ' 0 = table, 1 = query, 2 = SQL-statement
oMailMerge.Command = sSQL
oMailMerge.OutputType = 2 ' 1 = Printer, 2 = file, 3 = mail
oMailMerge.OutputURL <= sOutputURL>
oMailMerge.SaveAsSingleFile = TRUE
oMailMerge.execute(Array())
I need to perform mail merge without the use of a registered datasource.
Fields belonging to a datasource in the .odt are allowed.
A tab-delimited .txt file is provided. Converting that to an .ods is no problem.
So for the oMailMerge object, I use the name of the (not used) .odb (datasource), and the name of the table that is used in both the .ods and the .odb.
But, as pointed out above ... I do miss something to make it work.
Any hints?
Thanks - Cor