2

I have tried this;

var excelPicture = sheet.Drawings[0] as OfficeOpenXml.Drawing.ExcelPicture;
var img = excelPicture.Image;

However the excelPicture variable become null. How can I create image file from ExcelDrawing??

wonea
  • 4,783
  • 17
  • 86
  • 139
Onchomngebul
  • 63
  • 2
  • 8
  • If you're open to using another library, you should look into oxyplot: https://github.com/oxyplot/oxyplot I use this to embed images into reports in an internal API. – John Tesmer Aug 07 '19 at 14:28

1 Answers1

4

It seems that this can't be done via EPPlus API. There is the opened issue in the GitHub project repository how export the drawings to a file. But the provided solution in the question does not work (it seems @Onchomngebul himself wrote the the comment)

Alternative solution is to use Workbook class in Spire.XLS nuget-package (or via free version FreeSpire.XLS).

var workbook = new Workbook();
workbook.LoadFromFile(workbookFileName, ExcelVersion.Version2010);
var sheet = workbook.Worksheets[0]; // index or name of your worksheet
var image = workbook.SaveChartAsImage(sheet, 0); // chart index
img.Save(chartFileName, ImageFormat.Png);

For more details please see this comment in the issue.

Another solution is to try to use Excel.ChartObject. I think this question Exporting Excel Charts as Images may help you.

Didgeridoo
  • 1,222
  • 2
  • 14
  • 21