We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Copying data from DataSet ( grid ) in to Excel spreadsheet

Hi All,

I am using Aspose cells for the first time and I need to copy a data grid into an excel spreadsheet.
Could any one suggest me where I can find relevant information on this? I’m thinking copying cell by cell can be expensive if the data grid is very large. Just wondering, is there any other better way for doing this?

Please let me know.

Regards.

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

Thank you for considering Aspose.

You can use worksheet.Cells.ImportDataGrid(dataGrid,0,0,false); to import the data from a datagrid to work sheet. Please see the sample code which will help you get your desired results

Sample Code:-

sheet.Cells["A1"].PutValue("Import a DataGrid");

sheet.Cells["A1"].Style.Font.IsBold = true;

DataTable dataTable = new DataTable("Products");

dataTable.Columns.Add("Product ID", typeof(Int32));

dataTable.Columns.Add("Product Name", typeof(string));

dataTable.Columns.Add("Units In Stock", typeof(Int32));

DataRow dr = dataTable.NewRow();

dr[0] = 1;

dr[1] = "Aniseed Syrup";

dr[2] = 15;

dataTable.Rows.Add(dr);

dr = dataTable.NewRow();

dr[0] = 2;

dr[1] = "Boston Crab Meat";

dr[2] = 123;

dataTable.Rows.Add(dr);

DataGrid dataGrid = new DataGrid();

dataGrid.DataSource = dataTable;

dataGrid.UseAccessibleHeader = true;

dataGrid.ShowHeader = true;

dataGrid.DataBind();

sheet.Cells.ImportDataGrid(dataGrid,0, 0, true);

sheet.AutoFitColumns();

Please see the following link for more information regarding the data import to a worksheet from a datagrid.

http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/importing-data-to-worksheets.html

Thanks for your response. Its very helpful example too. will give this a shot.
Regards,