Free Support Forum -

Generate document for each row on a gridview


I used Aspose Word six months ago or so to generate documents from an .aspx screen using 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?


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:

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:

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.


Daniel Pierce


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:

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,