Free Support Forum - aspose.com

How can I fill multiple rows with doc.getMailMerge().execute(string[]- object[])

Hi ,

my doubt is that how can I fill multiple rows with

doc.getMailMerge().execute(new String[] {"FullName", "Company", "Address", "Address2", "City"},
//new Object[] {"James Bond", "MI5 Headquarters", "Milbank", "", "London"});

Means In word document I have the tages namely the above like FullName,Company,Address,Address2 and City.

Now I want to fill multiple rows using the execute method.

Actually I am getting this object data from Excel not from the result set.

How can I do that.

Or please please suggest me how can I fill multiple rows by getting objects.

my requirement is that

for(start rows)

for(start column)

create object with column data

for(column end)

doc.getMailMerge().execute(tage[],object[])

for(end row)

I want to fill multiple rows, which have same string names and I do not to mention the merge column for that many number of times in Word document since it is same.

Thanks

madhu

Hi Madhu,

I think you have placed your post in the wrong forum, I have moved it into the Aspose.Words forum.

Thank you.

Hi Amjad,

Thank you very much

Madhu

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. If you want to dynamically grow portions inside the document, use mail merge with regions. Please see the following link for more information:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/mail-merge-with-regions-explained.html

There is no way to fill multiple rows with execute(String[], Object[]) method.

In your case you also should use IMailMergeDataSource because you are using custom data source. Please see the following link to learn more.

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/com/aspose/words/imailmergedatasource.html

I hope this could help you.

Best regards.

Hi Alexey,

Thanks for your reply.

I read the two links and it seems that, they are mainly dealing with the database, not with the Strings which are repeating.

Can you help me by providing some other links or code in java.

Thanks

Madhu

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Sorry for delay. Actually I meant that you should use mail merge with regions and as data source you should use IMailMergeDatasource. You should implement your own class that inherits IMailMergeDatasource as described in the following article:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/com/aspose/words/imailmergedatasource.html

Please see the attached example.

Hope this helps.

Best regards.

Hi Alexey,

Thank you your reply. I will go through the link and I will get back to you.

Thanks

Madhu

Hi Amjad,

How can I insert data at particular location in Word Document.

What I mean is that I have a word template,which have some pre-defined headings and formattings and I want to add some dynamic text to that document.

Can you help me how can I acheive that?

Thnaks

Madhu

Hi alexey I have implemented the same example given by you.

But I am getting Out of Memory Exception.

Can I know waht is the reason, why it is displaying like this .

One more thing the customerList class is not allowing me to declare get and set methods(It is showing you are trying to overwrite the method kind og error.). so, I gave the methods as Get and Set and I changed the names appropriately in the following code

if (fieldName.equals("FullName"))
{
fieldValue[0] = mCustomers.Get(mRecordIndex).getFullName();
return true;
}
else if(fieldName.equals("Address"))
{
fieldValue[0] = mCustomers.Get(mRecordIndex).getAddress();
return true;
}

And everything is same as given .

But i am getting out of memory.

Here I am attaching my word documenmt .

Can you help me?

Thanks

Madhu

Hi Alexey,

Your code is working without out of memory exception. But, the output does not has all the records.

It si showing the first row only.

What about the rest.

Here si my output document.

I implemented the Example.zip given by you.

I made the only change is, as specified Get and Set methods of CustomerList class and getValue method of CustomerMailMergeDataSource class.

Waiting for your reply

Thanks

Madhu

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry.

1. You can use DocumentBuilder for inserting content at particular location in Word Document. You can use MoveToXXX methods to move DocumentBuilder cursor to a particular place or element in the document. See the following link for more information:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/moving-to-document-elements.html

2. Regarding your document. First of all you are using not correct field names for start and end of region. You are using StartTable:XXX but you should use TableStart:XXX.

I can’t reproduce the issue (“our of memory exception”) on my side. Could you please provide me more information about how I can reproduce this? Maybe you are using old version of Aspose.Words. I use the latest version for testing.

Also please see the attached documents.

Best regards.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

It seems that you are using “execute” method instead “executeWithRegions”.

Best regards.

Hi Alexey,

Thank you very much and it is working.

Thanks

Madhu