peterv6i General User


Joined: 13 Jun 2005 Posts: 36
|
Posted: Mon Dec 19, 2005 12:55 am Post subject: How to overwrite a file created with OpenOffice API? |
|
|
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). |
|