I have a dotnet core 2.1 web api that has an action that generates a .xlsx spreadsheet. It creates a FileStreamResult that the browser can then handle. The code to generate the spreadsheet is like so:
using (var excelFile = new ExcelPackage())
using (var worksheet = excelFile.Workbook.Worksheets.Add("Sheet 1"))
{
...
//insert data into worksheet
return new FileStreamResult(new MemoryStream(excelFile.GetAsByteArray()), "application/octet-stream") { FileDownloadName = "Report.xlsx" };
}
Hosting this in IIS works fine and will generate the spreadsheet.
When I host the app in a windows docker container specifically the image: microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016
I get the following exception when trying to generate the report:
System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'gdiplus.dll'
After a bit of research I realise gdiplus is not present in the nanoserver image.
Is it possible to use EPPlus to create a spreadsheet on a dotnet core app hosted in the nanoserver image? Or will I have to use another library to generate the xlsx? I'd like to use EPPlus if possible. I cannot use a linux container (for now anyway unfortunately)
I don't know if it will work, but try commenting out any of the methods from the library that uses System.Drawing.Common
, such as AutoFitColumns()
. That is what was causing it to break on my linux container.