c# exporting data from datagridview into excel

i have a winforms application and i want to export data from the datagridview into excel. how would i do this? thank u for any help

i want the simplest approach.

maybe exporting to CSV is easier?


You have a number of options

  • Write the data to a comma separated value (csv) file
  • Use OleDB to write to create an Excel file and write the data to it
  • Use the OOXML SDK to create an Excel file
  • Write the data to an XML file that can be read by Excel
  • Use the NPOI library to create and write to the Excel file
  • Those are a few options off the top of my head. Personally I would go with NPOI, I have used this in server based solutions and it is really easy to work with and quite fast. However it does not currenly support the xlsx file format, only standard xls. The library can be found here

    I also found EPPlus, supports xlsx, but I cannot vouch for it since I have not personally used it.


    The simplest approach would be to write the data to an XML file and then import that into Excel.

    There's a WriteXML method on the DataTable class that will write the schema out as well so when you import it into Excel all your column headings will be imported as well.

    It has the added advantage that you can import the data into other XML aware packages as well.


    There are many ways if you search Google. Here is one:

    http://www.c-sharpcorner.com/UploadFile/hrojasara/2904/

    链接地址: http://www.djcxy.com/p/36770.html

    上一篇: 大型datagridview导出为ex​​cel

    下一篇: c#从datagridview导出数据到excel