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

How to overwrite a file created with OpenOffice API?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
peterv6i
General User
General User


Joined: 13 Jun 2005
Posts: 36

PostPosted: Mon Dec 19, 2005 12:55 am    Post subject: How to overwrite a file created with OpenOffice API? Reply with quote

I write a simple example using mailmerge.. I have a defined datasource , csv file and template file which name is test.odt

Whe i execute a java program the output file saved on disk is: test1.odt.. etc..

How to implement or set the property that openoffice overwrite a existing file or how to create a new file in which the merged document will be saved?

here is a simple example:

Code:

public void doMerge()
    {
        Object mmservice = null;
        try
        {
            mmservice = mxMCF.createInstanceWithContext("com.sun.star.text.MailMerge", mxComponentContext);
        }
        catch (Exception e)
        {
            System.err.println("Error getting MailMerge service: " + e);
            return;
        }


        XPropertySet oObjProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,mmservice);
        try
        {
            oObjProps.setPropertyValue("DataSourceName", mDataSourceName);
            oObjProps.setPropertyValue("Command", mTableName);
            oObjProps.setPropertyValue("CommandType",
                new Integer(com.sun.star.sdb.CommandType.TABLE));
            oObjProps.setPropertyValue("OutputType",
               new Short(com.sun.star.text.MailMergeType.FILE));
            [b]oObjProps.setPropertyValue("DocumentURL", mFileURL);[/b]
            //oObjProps.setPropertyValue("DocumentURL", "file:///c:/peter.ott");
            oObjProps.setPropertyValue("SaveAsSingleFile", new Boolean(true));
        }
        catch (Exception e)
        {
            System.err.println("Error setting MailMerge properties" + e);

            return;
        }

        XJob job = (XJob) UnoRuntime.queryInterface(XJob.class, mmservice);

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


I wolud like to.. have a input filename (template file) and output file name (where the merged document will be stored)..

Is there a property to set it?

(if you look at the code up you can see the oObjProps.setPropertyValue("DocumentURL", mFileURL); property.. If I change the FileURL i get the Exception... (i wolud like to save the merged document with diferent name and it must be rewritable).
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API 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