MailMerge with regions of same name

Hi,

I have problem with MailMerge with regions of same name.
Document has more regions with same DataTable name and after I run application only the first one is merged.

I see that this is covered in documentation:

"Duplicate regions with the same name are allowed. However successfully merging duplicated regions depends on the type of data source being used for mail merge:

  • If an IMailMergeDataSource data source or a DataSet is used then duplicate regions will be merged automatically. This is due to the “root” structure of these data source types. Each region in the document is passed to these data sources and merged regardless of whether they are duplicates or not."

So, I’ve changed my code and join all DataTable objects into one DataSet and connect them with relations, but It’s the same.

The snippet of code:

*DataSet ds = new DataSet();
PreparedStatement ps_pol = con.prepareStatement(“select * from master_table”);

ResultSet rset_pol = ps_pol.executeQuery();
DataTable dt_pol = new DataTable(rset_pol, “MasterTable”);
ds.getTables().add(dt_pol);
PreparedStatement ps_det14 = con.prepareStatement(“select * from detail_table”);
ResultSet rset_det14 = ps_det14.executeQuery();
DataTable dt_det14 = new DataTable(rset_det14, “DetailTable”);
ds.getTables().add(dt_det14);

ds.getRelations().add(new DataRelation(“Test”, dt_pol.getTableName(), dt_det14.getTableName(),new String[]{“id”}, new String[]{“id”}));
Document doc = new Document (“C:/Test.doc”);
doc.getMailMerge().executeWithRegions(ds);
doc.save(“C:/TestMerged.doc”);*

I’ve tried this with 11.2 and 10.6 versions.

Any solution?

Thanks in advance for help.

Best regards,
Marko

Anyone? Please help, it’s critical!

Br,
Marko

Hi Marko,

Thanks for your inquiry and sorry for the delayed response. We’ve started working over your query and will get back to you soon.

Hi Marko,

Thanks for the inquiry. While using latest version of Aspose.Words 11.2.0. I could not reproduce this problem on my side. I have attached template document along with Output.

DataSet ds = GetResultSet("select  from Table1"); 
Document doc = new Document("C:/temp/test121/Template.docx");
doc.getMailMerge().executeWithRegions(ds);
doc.save("C:/temp/test121/Output.docx");

I hope this will help. In case of any ambiguity, please let us share sample Word document.

Hi Imran,

I don’t know what’s the problem. Maybe with creation of DataSet.
I’ve tried to create everything again, from scratch, but no luck. Only the first region is replaced.
I’ve added Java source files (Ecplise project export) and template document

Br,
Marko

Hi Marko,

Thanks for the inquiry.

In your code, Could you please change table name according Word template as “Test” and make sure that database table contains only two columns with name token_a and token_b and let us know how it goes on your side. Please also share output document here.

PreparedStatement ps_pol = con.prepareStatement("select * from table1");
ResultSet rset_pol = ps_pol.executeQuery();
DataTable dt_pol = new DataTable(rset_pol, "Test");

I hope, this will help.

Hi Imram,

Thanks for quick response.

Table definition is:
create table table1(
token_a VARCHAR2(100),
token_b VARCHAR2(100)
);

insert into table1 (token_a, token_b) values (‘Token A val 1’, ‘Token B val 1’);
insert into table1 (token_a, token_b) values (‘Token A val 2’, ‘Token B val 2’);

I’ve even tried to rename DB table to test. Again, no luck.
Output file is in attachment.

Br,
Marko

Hi Marko,

Thanks for the inquiry and sorry for delay. I’m afraid. I’m still unable to reproduce this problem on my side. Could you please share which JDK version you are using?

Hi Imran,

it’s JDK 1.6.0.220.

I’ve event tried with 1.7.0.30, but no luck either.

Did you tried to run my code in your environment?

Br,
Marko

Hi Marko,

Thanks for the inquiry and sorry for delay. Could you please try it with another option of IMailMergeDataSource and let us know how it goes on your side?
https://reference.aspose.com/words/net/aspose.words.mailmerging/imailmergedatasource/

Moreover, I have tried your Word template with Netbeans 7.0.1, JDK 1.6.

I hope, this will help.

Hi Marko,

Are you still experiencing this issue of unable to merge duplicate regions? Please let us know and we will look into this issue further to try reproduce it.

Also note that I have also linked this thread for a request to duplicate mail merge regions when using DataTable and IMailMergeDataSource. This should it easier to achieve this sort of thing in the future by just using DataTable.

Thanks,

Hi,

Yes we’ve managed to solve this problem by replacing ResultSet object with CachedRowSet object.
Problem was probably with cursor position in this ResultSet object. After first loop it probably returned false.

Br,
Marko

Hi Marko,

Thanks for this additional information.

It’s great your issue was solved. Yes that it is a good point to keep in mind. I will add this to the documentation.

Thanks,

The issues you have found earlier (filed as WORDSNET-5290) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(1)