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

Problem creating document when mail merging

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


Joined: 02 Jun 2005
Posts: 4

PostPosted: Sat Jun 25, 2005 5:46 am    Post subject: Problem creating document when mail merging Reply with quote

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
View user's profile Send private message
Cybb20
Super User
Super User


Joined: 02 Mar 2004
Posts: 1569
Location: Frankfurt, Germany

PostPosted: Sat Jun 25, 2005 4:22 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
apj
Newbie
Newbie


Joined: 02 Jun 2005
Posts: 4

PostPosted: Sun Jun 26, 2005 4:20 am    Post subject: Reply with quote

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
View user's profile Send private message
apj
Newbie
Newbie


Joined: 02 Jun 2005
Posts: 4

PostPosted: Sun Jun 26, 2005 10:13 am    Post subject: Reply with quote

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
View user's profile Send private message
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