copying data from DataSet ( grid ) in to Excel spreadsheet.

Last post 11-10-2008, 6:49 PM by myaspose2020. 2 replies.
Sort Posts: Previous Next
  •  11-10-2008, 12:21 AM 151712

    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.
     
  •  11-10-2008, 12:43 AM 151714 in reply to 151712

    Re: copying data from DataSet ( grid ) in to Excel spreadsheet.

    Hi,

    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


    Nausherwan Aslam
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
  •  11-10-2008, 6:49 PM 151852 in reply to 151714

    Re: copying data from DataSet ( grid ) in to Excel spreadsheet.

    Thanks for your response. Its very helpful example too. will give this a shot.
    Regards,
     
View as RSS news feed in XML