How to get OleDb for reading excel in asp.net core project

后端 未结 2 554
花落未央
花落未央 2021-01-13 21:44

Is there any way of reading excel data in ASP.NET Core (built over .Net Core)? I am not able to refer OleDB in project.json of my .net

2条回答
  •  灰色年华
    2021-01-13 21:59

    As indicated by andrews, it is recommended to use a third-party library, especially when working with formatting. An alternative to ClosedXML is EPPlus. For most of my project I have used ClosedXML, but I had to switch to EPPlus because it has support for charts.

    For ASP.NET Core, you can use EPPlus.Core. I have performed a quick test within an ASP.NET Core 2.0 console app and it seems to work fine:

    var newFile = new FileInfo("some file.xlsx");
    using (ExcelPackage xlPackage = new ExcelPackage(newFile))
    {
       var ws = xlPackage.Workbook.Worksheets.Add("etc");
       ws.Cells[1, 1].Value = "test";
    
       // do work here 
       xlPackage.Save();
    }
    

提交回复
热议问题