How to create excel file with multiple sheets from DataSet using C#

后端 未结 2 1043
遥遥无期
遥遥无期 2021-01-02 05:37

How to create excel file with multiple sheets from DataSet using C#. I have successfully created an excel file with single sheet. But I am not able to do that for multiple

2条回答
  •  离开以前
    2021-01-02 05:56

    var groupedSheetList = UserData
        .GroupBy (u => u.date)
        .Select (grp => grp.ToList ())
        .ToList ();
    

    You can try this

    using (var package = new ExcelPackage ()) 
        {
            foreach (var item in groupedSheetList) {
                var workSheet = package.Workbook.Worksheets.Add (item[0].date);
        }
    }
    

提交回复
热议问题