DataGrid samples


I am evaluating products to use in a current project and would like to test Aspose quickly. I need to export multiple DataGrids to multiple workbook sheets. Where can I get a sample to use as a template/example to learn how this is done with Aspose?


It’s easy to import datagrids with Aspose.Excel. You can try the following code:

Excel excel = new Excel();

excel.Worksheets[0].Cells.ImportDataGrid(this.dataGrid1, 1, 1, this.dataGrid1.Items.Count, this.dataGrid1.Columns.Count, true);

excel.Worksheets[1].Cells.ImportDataGrid(this.dataGrid2, 1, 1, this.dataGrid2.Items.Count, this.dataGrid2.Columns.Count, true);

excel.Worksheets[2].Cells.ImportDataGrid(this.dataGrid3, 1, 1, this.dataGrid3.Items.Count, this.dataGrid3.Columns.Count, true);


Ok, that works. Now the next step - how do I send the excel file to the browser?

The goal is to send the contents of a datagrid to the user as an excel document.



Hi Wes,

After you import data from the datagrids, you can use Excel.Save method to send the result file to the user.

excel.Save(“book1.xls”, SaveType.OpenInExcel, FileFormatType.Default, this.Response);


Ah! So simple. Hmmm - but one problem - all my Datagrid header and formatting are gone - can those be exported also?



Hi Wes,

I will investigate this feature and I think it’s feasible. But I have lost of other feature requests on hand. So it will not be availabe in a short time.


So this is not available at this time? How about exporting a datagrid to a template that contains the headers?



Not availabe right now. I will think about importing datagrid headers in Aspose.Excel. Now you can try to export the headers with your own code.