locked
Data transfer from dataset to excel RRS feed

  • Question

  • I am working on a project in Visual studio 2005 / vb.

    I have some records displayed in a datagrid which is bound to an object (class) data source. I need to transfer all this data to excel. Is there a simple way to do this???

    Friday, April 27, 2007 1:30 PM

All replies

  • Programmatically or manually? Manually, select all of the data in the grid using Ctrl+A. Then paste into Excel. Programatically, none of the ways are particularly simple. You have to either use Excel Interop, or open the Excel workbook as an OleDb database. There are many threads on both methods in these forums. Try searching for them.
    Friday, April 27, 2007 6:14 PM
  • There are many options to do it but it is good if you have a ado.net datatable instead of custom object source.

    Option-1

    A simple option is to use DataTable.WriteXML(filename) and set the filename to a filename with extension as .xls. This is not going to be an .xls but will open smoothly in excel.

    Option-2 (Need Asp.net Gridview)

    Fill your object data source to a gridview and use Response.Wrtie with ContentType = "application/vnd.ms-excel" configured to export to Exceel. A good example you can use from here,

    http://blog.weareon.net/export-datatable-to-excel-in-asp-net-without-using-excel-interop-part-ii/

    Option-3

    Use COM Interop to create a Excel file. Refer http://janewdaisy.wordpress.com/2011/03/21/two-methods-to-export-data-from-dataset-to-excel-using-c/

    There is no built in class/method in ado.net for exceel except oledb. But you can apply any kins of formating using oledb.


    Lingaraj Mishra


    Monday, May 7, 2012 12:58 PM