Free Support Forum - aspose.com

Generate document for each row on a gridview

Hi,

I used Aspose Word six months ago or so to generate documents from an .aspx screen using VB.net. The users now have a new request for another screen. They want to upload data from an Excel spreadsheet into a word template.

I plan to import the data into a gridview on screen from the excel spreadsheet when the user clicks on a button. Then using aspose, I want to generate a document using the ".dot" template provided for each row on that gridview when the user clicks a second button. I want to keep it as simple as possible for the users. At the moment I don't know how much data is in the spreadsheet, but I think there could be over a hundred rows of information, which may vary from month to month.

Is this possible? Is this the best approach?

Regards,

Daniel Pierce

Hi Daniel,

Thanks for your request. I can suggest you at least two ways to achieve what you need.

1. If you simply need to convert Excel file to Word document, you can use Aspose.Words+Aspose.Cells to achieve this. You can find a demo called Excel2Word that demonstrates the technique of conversion here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/entry187174.aspx

2. Second approach presumes that data in your Excel document has a certain set of columns. In this case, you can use Mail Merge with Regions feature:

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

Your Excel document will be a data source for mail merge.

Hope this could help you.

Best regards,

Thanks Alexey,

Neither of the solutions you have offered quite meet our requirements. We don't have Aspose.Cells so the first solution isn't an option for us. While the mail merge, from what I understand, will present the information in a table on a word document, which is not the presentation being requested, please correct me if I'm wrong.

One of the other samples in the download, however, 'MultipleDocsInMailMerge' will probably do what I want. I found some other code on the internet which will allow me to import data from Excel into a "dataTable" object, and this aspose example allows me to create a document (based on my ".dot" template) for each row on the this "dataTable".

I'm still in the theory stage of this development, so if I've misunderstood the second solution you've referred to then could you please explain in a bit more detail? Or if my alternative using the 'MultipleDocsInMailMerge' sample will not work or there are potential pitfalls could you please let me know, thank you.

Regards,

Daniel Pierce

Hi

Thank you for additional information. I did not get your requirements right. Now I understand what you need and I think the approach suggested in this article will allow you to achieve what you need:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-produce-multiple-documents-during-mail-merge.html

The only thing you should do is to read your Excel file into an object that will be convenient to use for mail merge, for example into DataTable.

Best regards,