OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Mailmerge from java program with OO 3.1

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
tomahawk73
Newbie
Newbie


Joined: 18 Mar 2011
Posts: 1

PostPosted: Fri Mar 18, 2011 1:21 am    Post subject: Mailmerge from java program with OO 3.1 Reply with quote

I' have develop a jdbc driver that read from a custom data structure.Now I need to use
the mailmerge service to create documents from this data.
Using Writer mailmerge function all go well but when i try to use a java
program using UNO I've met this Exception

Caught UNO Exception: com.sun.star.uno.Exception: Mail merge failed. Sorry, no further information available.

in
Code:

 job.execute(new NamedValue[] {});


OpenOffice 3.1
O.S.: Windows XP service pack 2


Code:

        try {
            // Create an instance of the MailMerge service
            mmservice = mxMCF.createInstanceWithContext(
                "com.sun.star.text.MailMerge", mxComponentContext);
        }
        catch (Exception e) {
            System.err.println("Error getting MailMerge service: " + e);
            return;
        }
        try {
            XRowSet xRowSet = (XRowSet)UnoRuntime.queryInterface(XRowSet.class, mxMSF.createInstance("com.sun.star.sdb.RowSet"));
            XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(
                XPropertySet.class, xRowSet);
            xProp.setPropertyValue("User",<USER>);
            xProp.setPropertyValue("Password",<password>);
            xProp.setPropertyValue("DataSourceName", DATASOURCENAME);
            xProp.setPropertyValue("CommandType",
                new Integer(com.sun.star.sdb.CommandType.TABLE));
            xProp.setPropertyValue("Command",TABLE_NAME);
            xRowSet.execute();

            // Get the XPropertySet interface of the mmservice object
            XPropertySet oObjProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, mmservice);
            oObjProps.setPropertyValue("ResultSet", xRowSet);
            oObjProps.setPropertyValue("DocumentURL", "file:///C:/doc.ott");
               oObjProps.setPropertyValue("OutputType",com.sun.star.text.MailMergeType.FILE);
           
            oObjProps.setPropertyValue("SaveAsSingleFile",new Boolean(false));
            oObjProps.setPropertyValue("OutputURL","file:///C:/files");

        // Get XJob interface from MailMerge service and call execute on it
        XJob job = (XJob) UnoRuntime.queryInterface(XJob.class, mmservice);

        try {
            job.execute(new NamedValue[] {});
        }
        catch (com.sun.star.lang.IllegalArgumentException iae) {
            System.err.println("Caught IllegalArgumentException: " + iae);
        }


Thanks for help.

PS: Sorry for my english.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group