c# (WinForms-App) export DataSet to Excel

后端 未结 8 2102
野趣味
野趣味 2020-12-04 14:46

I need a solution to export a dataset to an excel file without any asp code (HttpResonpsne...) but i did not find a good example to do this...

Best thanks in advance

8条回答
  •  我在风中等你
    2020-12-04 15:26

    The following site demonstrates how to export a DataSet (or DataTable or List<>) into a "genuine" Excel 2007 .xlsx file.

    It uses the OpenXML libraries, so you don't need to have Excel installed on your server.

    C# ExportToExcel library

    All of the source code is provided, free of charge, along with instructions using it with ASP.NET, ASP.NET Core 2+ or regular C#.

    It's very easy to add to your own applications, you just need to call one function, passing in an Excel filename, and your data source:

    DataSet ds = CreateSampleData();
    string excelFilename = "C:\\Sample.xlsx";
    CreateExcelFile.CreateExcelDocument(ds, excelFilename);
    

    Hope this helps.

提交回复
热议问题