Issue upgrading to latest version of Aspose.Words for Java

Hi,
I am trying to upgrade our code to use the latest version of Aspose.Words (for Java). I am facing an issue passing WebRowSet to doc.getMailMerge.execute method. The invocation is as below,

doc.getMailMerge.execute(oammRowSet);

Can I please get some guidance on whether this is still supported?
Thanks,
Praveen

Hi Praveen,

Thanks for your query. Please read the supported execute methods of MailMerge class from following documentation link.

https://reference.aspose.com/words/java/com.aspose.words/MailMerge

Let us know, If you have any more queries.

Hi Tahir,
Many Thanks for the link. I guess from the section below what we are doing seems to be fne,
execute
public voidexecute(DataTabletable)
throws java.lang.Exception

Parameters:
All records from the table are merged into the document.
Parameters:
Example:

Document doc = new Document(getMyDir() + "MailMerge.ExecuteDataTable.doc");
// This example creates a table, but you would normally load table from a database.

java.sql.ResultSet resultSet = createCachedRowSet(new String[] {"CustomerName", "Address"});

addRow(resultSet, new String[] {"Thomas Hardy", "120 Hanover Sq., London"});

addRow(resultSet, new String[] {"Paolo Accorti", "Via Monte Bianco 34, Torino"});

com.aspose.words.DataTable table = new com.aspose.words.DataTable(resultSet, "Test");

// Field values from the table are inserted into the mail merge fields found in the document.

doc.getMailMerge().execute(table);

doc.save(getMyDir() + "MailMerge.ExecuteDataTable Out.doc");

I am getting an error message trying to compile the program where the execute method gets invoked. Will you be able to provide an any input on the same.
The error is as below,

C:\695762\JavaOffice\com\cedar\office\operation\MailWord.java:122: cannot find symbol
symbol : method execute(com.cedar.office.OammRowSet)
location: class com.aspose.words.MailMerge
doc.getMailMerge().execute(oammRowSet);
^

I’ve attached the MailMerge.java program as MailMerge.txt
Can you see any reason why this error is raised?
Many Thanks,
Praveen

Hi Tahir,
I’ve done some more work on this and have sorted the error. The processing of RowSet doesn’t happen and my mail merge fails now.
Can you please let me know whether this is a known bug or the way I am going is not right? I am following the implementation as specified in the documentation provided in the link posted by you.
I am attaching the latest version of MailMerge.java which doesn’t error as MailMerge.txt.
Can you please look at this and let me know? We had an issue with the existing version to do with Page Breaks and hence need to see whether the latest version caters for that. We have the 30 day trial license for the latest version and would like to buy the latest version if the issue is catered for.
Please do let me know if you need any further information.
Thanks,
Praveen

Hi Praveen,

Thanks for sharing the information. I have checked your code and it seems that it is not complete code. Please use the latest version of Aspose.Words for Java. If you still face problem then please share your complete code along with data source for investigation purposes.

Many Thanks Tahir for getting back. I am trying with the latest version of Aspose.Words. I am attaching two more programs which should help to illustrate the whole picture.
I am also attaching the Merge Data source file and the Template file I am using for testing.
Please change the extension of OammRowSet.txt and WebRowSetWriter.txt to .java
mmstat.doc is the Template and 52700005.txt is the Mail merge data source file.
Can you please let me know if you need any more files?
Thanks,
Praveen

Hi Praveen,

Thanks for sharing the information. I am unable to execute your code as this code gives me a lot of errors. However, I have tested the following example with your document and have not found any issue while using latest version of Aspose.Words for Java. Can you please share, which JDK version you are using?

Document doc = new Document(getMyDir() + "MailMerge.ExecuteDataTable.doc");

// This example creates a table, but you would normally load table from a database.
java.sql.ResultSet resultSet = createCachedRowSet(new String[] {"CustomerName", "Address"});
addRow(resultSet, new String[] {"Thomas Hardy", "120 Hanover Sq., London"});
addRow(resultSet, new String[] {"Paolo Accorti", "Via Monte Bianco 34, Torino"});
com.aspose.words.DataTable table = new com.aspose.words.DataTable(resultSet, "Test");

// Field values from the table are inserted into the mail merge fields found in the document.
doc.getMailMerge().execute(table);

doc.save(getMyDir() + "MailMerge.ExecuteDataTable Out.doc");

Hi Tahir,
Thank you for the response. Please find attached the document we get as a result of MailMerge. Please see page 4 to see the issue.
The JDK version I am using is 1.5.0_15.
Can you also let me know whether our implemantation of WebRowSet is compatible with the latest version of Aspose.Words.
Many Thanks,
Praveen

Hi Praveen,

Thanks for sharing the document. I like to share with you that this is not an issue, you are using the simple mail merge. Please use mail merge with regions.

I have modified your source document. Please find modified document and output document in attachment.

Hi Tahir,
I’ve tried here with no success. With the latest version of Aspose.Words my mail merge doesn’t happen and I end up with the source document. Did you try with WebRowSet?
I did try with executeWithRegions(new DataTable(oammRowSet)).
Please do let me know.
Thanks,
Praveen

Hi Praveen,

Please check the documentation of DataTable. The constructor take arguments as ResultSet not WebRowSetImpl. Please use the following code snippet for your scenario. I have attached the document files with this post.

Document doc = new Document("D:\\mmstat_modified.doc");
Connection objConn = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
objConn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=d:\\mailmerge.mdb");
String strQuery = "Select * from mailmerge";
Statement objStatement = null;
ResultSet rst = null;
objStatement = objConn.createStatement();
rst = objStatement.executeQuery(strQuery);
com.aspose.words.DataTable dt = new DataTable(rst, "Aspose");
doc.getMailMerge().executeWithRegions(dt);
doc.save("D:\\out.doc");

If this does not helps you, please share you complete scenario so that we can help you in detail.
Thanks.

Hi Tahir,
Thank you for getting back to me. Our current program which uses old version of Aspose.Words uses WebRowSetImpl to read mail merge data file. This fails with the new version. Apart from the one document where the page break was getting skipped we never had much issues. That is the only reason for the upgrade.
If you see OammRowSet.java and WebRowSetWriter.java which I attached previously, you should be able to see the processing of standard mailmerge datafile using WebRowSetImpl. There is processing there to handle the first row which is column headings and data in rest of the rows. Since WebRowSet can expose data as XML, has anyone at your end tried using that XML with XMLMailMergeDataTable class? I am trying to make as little change as possible since what we have now is time tested one. If XMLMailMergeDataTable will work in our scenario then I would like to progress that path and hence the query.
Can you please let me know.
Thanks,
Praveen

Hi Praveen,

For XMLMailMergeDataTable, Please read example at following documentation link for your kind reference. Let me know, If you have any more query.

https://docs.aspose.com/words/java/mail-merge-with-xml-data-source/

Hi Tahir,
I am trying to compile the XmlMailMergeDataTable.java from
https://docs.aspose.com/words/java/mail-merge-with-xml-data-source/
and the following message gets displayed,
XmlMailMergeDataTable.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
I tried compiling with -Xlint :unchecked and got the follwing message,
XmlMailMergeDataTable.java:150:warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.HashMap mExpressionSet.put(path, expression);
Is there an updated version of this code? Please do let me know.
Thanks,
Praveen

Hi Praveen,

Please use the latest version of Aspose.Words for Java. I have attached the code, source document and output document with this post. Please check the code and output document.

Hi Tahir,
Thank you for the update. I’ve tried with the latest programs you have supplied and I do get the breforementioned message with the latest XmlMailMergeDataTable.java. Are you not getting the same when you compile? Is that the final version that you are recommending to be used?
Cheers,
Praveen

Hi Praveen,

Thanks for your feedback. I did not get any exception with code shared at following documentation link.

I shared the output file as well in my last post. I used the same code mentioned at following documentation link. Are you using the latest version of Aspose.Words for Java?

https://docs.aspose.com/words/java/mail-merge-with-xml-data-source/

Hi Tahir,
I am using the latest version of Aspose.Words and when I compile XmlMailMergeDataTable.java from the weblink or from the zip file you previously attached I got those message.
Didd you try with the JDK version similar to mine?
Cheers,
Praveen

Hi Praveen,

Thanks for your inquiry.

The message you are seeing in the code is just a warning and is not very important. Please feel free to ignore it. I will look into fixing this warning in the code.

Thanks,

Hi,
Thank you for getting back to me. My Java experience and knowledge is limited to this exercise of migrating to latest version of Aspose.Words and hence my query.
I am almost there with the migration. My data do get merged now apart from the first line. This seems to be missing. I am exporting the data which is being sent for mailmerge to an xml file as well (as we use WebRowSet) and I can see that the entire data is getting passed. The legacy code used WebRowSetImpl and I was told that is not supported by DataTable class. I was planning to export data from WebRowSetImpl class as XML and then use Aspose mail merge with XML data instead. I saw some issue with the data source from XML output and rectified the same. I tried again with WebRowSet as it has inheritance from ResultSet and DataTable wraps the ResultSet. This seems to be working as mailmerge does happen.
I am attaching the latest version of programs along with the word template and data source file. Please can this be looked at. I am also attaching the dump of data source as XML.
Programs: MailWord.java, OammRowSet.java & WebRowSetWriter.java
Word Template: mmstat.doc, Data Source - 52700005.oamm
Dump of data souce as XML file - jobs.xml
Thanks,
Praveen