[Solved] python uno script mail merge

Java, C++, C#, Delphi, ??? - Using the UNO bridges

[Solved] python uno script mail merge

Postby moriatynz » Sat Nov 24, 2018 7:35 am

I've been trying to get a mail merge script to execute using the python shipped with OOo 4.1.6. It gives me an error when it gets to the execute statement, it throws an exception:

File "trymerge.py", line 20, in mergeit
oMailMerge.execute([])
__main__.RuntimeException: <type 'exceptions.AttributeError'>: 'list' object has no attribute 'getTypes', traceback follows
no traceback available


Passing nothing at all: oMailMerge.execute() gives:
oMailMerge.execute()
__main__.IllegalArgumentException: incorrect number of parameters passed invoking function execute


What should I be passing to oMailMerge.execute?

Code: Select all   Expand viewCollapse view
import uno

def mergeit():
   localContext = uno.getComponentContext()
   resolver = localContext.ServiceManager.createInstanceWithContext(
      "com.sun.star.bridge.UnoUrlResolver", localContext )
   ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
   smgr = ctx.ServiceManager
   oMailMerge = smgr.createInstanceWithContext( "com.sun.star.text.MailMerge",ctx)
   oMailMerge.DocumentURL = "file:////home/user/templates/testtemplate.odt"  #Source document (forward slashes only)
   oMailMerge.DataSourceName = "jdbcpostgresmailmerge" #name of data source (included in source document)
   oMailMerge.CommandType = 0                                 #0 = table name, 1 = query name, 3 = SQL command
   oMailMerge.Command = "public.mailmergedata"                #name of table in data source
   oMailMerge.OutputType = 2                                  #1 = printer, 2 = file, 3 = email
   oMailMerge.OutputURL = uno.systemPathToFileUrl("/home/user/output/")    #output directory (forward slashes only)
   oMailMerge.SaveFilter = "writer8"
   oMailMerge.FileNameFromColumn = True       #get file name from data source column
   oMailMerge.FileNamePrefix = "mergefilename"      #name of data source column
   oMailMerge.SaveAsSingleFile = False        #save as multiple files
   oMailMerge.execute([])

def main():
   mergeit()

if __name__ == '__main__':
   main()
Last edited by robleyd on Sat Nov 24, 2018 8:49 am, edited 1 time in total.
Reason: Tagged [Solved] [robleyd, Moderator]
OpenOffice 4.1.6 Ubuntu 18.04 x86_64
moriatynz
 
Posts: 2
Joined: Sat Nov 24, 2018 6:49 am

Re: python uno script mail merge

Postby FJCC » Sat Nov 24, 2018 7:46 am

I am totally out of my depth here, but i think you have to pass a tuple to the execute() method, not a list.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7133
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: python uno script mail merge

Postby moriatynz » Sat Nov 24, 2018 8:37 am

Thank you, thank you, thank you @FJCC! I've been battling with this for half a day and now solved my problem. For the record, this works:
oMailMerge.execute((),)

Passing an empty tuple is indeed what was required.
OpenOffice 4.1.6 Ubuntu 18.04 x86_64
moriatynz
 
Posts: 2
Joined: Sat Nov 24, 2018 6:49 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 0 guests