Search code examples
c#exceldockerasp.net-coreepplus

EPPlus worksheet.Drawings.AddPicture() does not support Jpg/Png on docker


I am currently writing a program which generates a barcode and then saves it locally as image with a standard file extension (e.g. jpeg, png). After that I need to import the generated barcode image inside a newly created excel file using the worksheet.Drawings.AddPicture() method. Everything works while I run the program as a console application, but when I run it using Docker the following exception is thrown:

System.InvalidOperationException: No image handler for image type Jpg
   at OfficeOpenXml.Drawing.PictureStore.GetImageBounds(Byte[] image, ePictureType type, ExcelPackage pck)
   at OfficeOpenXml.Drawing.PictureStore.AddImage(Byte[] image, Uri uri, Nullable`1 pictureType)
   at OfficeOpenXml.Drawing.ExcelPicture.SaveImageToPackage(ePictureType type, Byte[] img)
   at OfficeOpenXml.Drawing.ExcelPicture.LoadImage(Stream stream, ePictureType type)
   at OfficeOpenXml.Drawing.ExcelDrawings.AddPicture(String Name, FileInfo ImageFile, Uri Hyperlink)
   at OfficeOpenXml.Drawing.ExcelDrawings.AddPicture(String Name, FileInfo ImageFile)

For the barcode generation I use ZXing.Net version 0.16.8. For the image generation I use ImageSharp version 2.1.3 (because, as far as I know, the standard System.Drawing.Common library is only supported on Windows)

string temporaryBarcodeImagePath = $"barcode.jpeg";

var barcodeMatrix = _barcodeManager.GenerateCode128(order.ReferenceNumber, 400, 20);
await _barcodeManager.SaveBarcodeImageAsync(temporaryBarcodeImagePath, barcodeMatrix);
var picture = worksheet.Drawings.AddPicture("Barcode", temporaryBarcodeImagePath);

picture.SetPosition(20, 20);

The _barcodeManager is just a service which generates and saves the barcode image locally in the file system. I don't think the problem could be related to it.

The only similar problem I have found so far was the following github issue: https://github.com/EPPlusSoftware/EPPlus/issues/645

However, in the issue is stated that the bug in question was fixed in EPPlus version 6.0.5, which is the exact version I am using currently.

Any help would be greatly appreciated. Thanks in advance!


Solution

  • I have provided some explanation in the following github issue thread:

    https://github.com/EPPlusSoftware/EPPlus/issues/645