Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

excel nuget package for .net core [duplicate]

I need some library for .net core to help me create an excel file (no matter the exact file extension).

I tried to use the MICROSOFT.OFFICE.INTEROP.EXCEL.DLL (windows dll), I searched for it in the nuget gallery, I tried to find other package with core support, but I didnt managed to find one.

Is there a library witch can help me?

like image 416
n_ananiev Avatar asked Nov 08 '16 13:11

n_ananiev


1 Answers

You should try EPPlus.Core:

Here is how to read an Excel using that library (tried myself here):

var filePath = @"D:/test.xlsx";
FileInfo file = new FileInfo(filePath);

using (ExcelPackage package = new ExcelPackage(file))
{       
    ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
    int rowCount = worksheet.Dimension.Rows;
    int ColCount = worksheet.Dimension.Columns;

    var rawText = string.Empty;
    for (int row = 1; row <= rowCount; row++)
    {
        for (int col = 1; col <= ColCount; col++)
        {   
            // This is just for demo purposes
            rawText += worksheet.Cells[row, col].Value.ToString() + "\t";    
        }
        rawText+="\r\n";
    }
    _logger.LogInformation(rawText);
}

And at the offictial page I've found a complete example in ASP.Net Core here: https://github.com/VahidN/EPPlus.Core/tree/master/src/EPPlus.Core.SampleWebApp

Juan

like image 188
Juan Avatar answered Nov 13 '22 23:11

Juan