How to export DataTable to Excel

后端 未结 21 2671
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 15:36

How can I export a DataTable to Excel in C#? I am using Windows Forms. The DataTable is associated with a DataGridView control. I have

21条回答
  •  甜味超标
    2020-11-22 15:40

    I would recommend ClosedXML -

    You can turn a DataTable into an Excel worksheet with some very readable code:

    XLWorkbook wb = new XLWorkbook();
    DataTable dt = GetDataTableOrWhatever();
    wb.Worksheets.Add(dt,"WorksheetName");
    

    The developer is responsive and helpful. The project is actively developed, and the documentation is superb.

提交回复
热议问题