| View previous topic :: View next topic |
| Author |
Message |
apj Newbie

Joined: 02 Jun 2005 Posts: 4
|
Posted: Sat Jun 25, 2005 5:46 am Post subject: Problem creating document when mail merging |
|
|
Hi everybody,
I do some mailmerging code but it fails when creating a document from url at this line:
oObjProps.setPropertyValue("DocumentURL", FileURL);
So please can anyone help, I researched but I haven't found any solutions. thx
this is a part of the code (the url transformation is necessary because I'm getting the url as a parameter from a swing component):
//do merging
Object mmservice = null;
System.out.println("implements merging doing");
try {;
// Create an instance of the MailMerge service
xRemoteServiceManager = xRemoteContext.getServiceManager();
mmservice = xRemoteServiceManager.createInstanceWithContext(
"com.sun.star.text.MailMerge", xRemoteContext);
}
catch (com.sun.star.uno.Exception e) {
System.err.println("Error getting MailMerge service: " + e);
return;
}
// Get the XPropertySet interface of the mmservice object
XPropertySet oObjProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, mmservice);
try {
System.out.println("datasource merging");
// Set up the properties for the MailMerge command
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.PRINTER));
StringBuffer inputURL = new StringBuffer("file:///");
inputURL.append(mFileURL.replace('\\', '/'));
String FileURL = (String)inputURL.toString();
oObjProps.setPropertyValue("DocumentURL", FileURL);
} catch (com.sun.star.uno.Exception e) {
System.err.println("Error setting MailMerge properties" + e);
return;
} |
|
| Back to top |
|
 |
Cybb20 Super User


Joined: 02 Mar 2004 Posts: 1569 Location: Frankfurt, Germany
|
Posted: Sat Jun 25, 2005 4:22 pm Post subject: |
|
|
Hi apj, have you checked if the url is correct (I see you do some string manipulations)?
Also please do provide the exact error message. If you give some more information, I will take a look since this is brandnew API stuff new in OOo 2.0
Christian _________________ - Knowledge is Power - |
|
| Back to top |
|
 |
apj Newbie

Joined: 02 Jun 2005 Posts: 4
|
Posted: Sun Jun 26, 2005 4:20 am Post subject: |
|
|
hi
*sorry*
the url is kind of "C:\\Programme\\OpenOffice.org1.1.4\\" - the string manipulation works because I use it when loading a text document too.
The error message is:
com.sun.star.uno.RuntimeException: Failed to create document from URL: file:///E:/dateien/fh/APJ2/OfficeFramework/serienbrief.sxw
thx |
|
| Back to top |
|
 |
apj Newbie

Joined: 02 Jun 2005 Posts: 4
|
Posted: Sun Jun 26, 2005 10:13 am Post subject: |
|
|
I've found my mistake and rewritten my code, now it looks like:
and theres's still a problem, because it prints as many sites as there are different rows, but doesn't fill the content, which means only the textfields can be seen, not the value behind them
StringBuffer inputURL = new StringBuffer("file:///");
inputURL.append(fileName.replace('\\', '/'));
PropertyValue[] properties = new PropertyValue[1];
properties[0] = new PropertyValue();
properties[0].Name = "As Template";
properties[0].Value = new Boolean(true);
document = this.officeComponentLoader.loadComponentFromURL(
inputURL.toString(), "_blank", 0, properties);
if (document==null)
throw new FileLoadException ("The file " +inputURL+ " couldn't be open");
Object mmservice = null;
System.out.println("implements merging doing");
try {
// Create an instance of the MailMerge service
xRemoteServiceManager = xRemoteContext.getServiceManager();
mmservice = xRemoteServiceManager.createInstanceWithContext(
"com.sun.star.text.MailMerge", xRemoteContext);
}
catch (com.sun.star.uno.Exception e) {
System.err.println("Error getting MailMerge service: " + e);
return;
}
// Get the XPropertySet interface of the mmservice object
XPropertySet oObjProps = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, mmservice);
NamedValue[] mailParam = new NamedValue[8];
StringBuffer outputURL = new StringBuffer("file:///");
outputURL.append(mFileURL.replace('\\', '/'));
String FileURL = (String)outputURL.toString();
System.out.println("datsourcename " +mDataSourceName);
mailParam[0] = new NamedValue("DocumentURL", inputURL.toString());
mailParam[1] = new NamedValue("DataSourceName", mDataSourceName);
mailParam[2] = new NamedValue("CommandType", new Integer(
com.sun.star.sdb.CommandType.TABLE));
mailParam[3] = new NamedValue("Command", mTableName);
mailParam[4] = new NamedValue("OutputType", new Short(
com.sun.star.text.MailMergeType.PRINTER));
mailParam[5] = new NamedValue("OutputURL", FileURL) ;
mailParam[6] = new NamedValue("FileNamePrefix", "auto");
// Get XJob interface from MailMerge service and call execute on it
XJob job = (XJob) UnoRuntime.queryInterface(XJob.class, mmservice);
try {
//job.execute(new NamedValue[1]);
job.execute(mailParam);
}
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);
} |
|
| Back to top |
|
 |
|
|
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
|