DataGrid samples


#1

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?


#2

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);


#3

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.

-Wes


#4

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);


#5

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

-Wes


#6

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.


#7

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

-Wes


#8

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.