如何将在 EPPlus 中创建的图表导出到图像文件
How to export Chart created in EPPlus to Image file
我试过了;
var excelPicture = sheet.Drawings[0] as OfficeOpenXml.Drawing.ExcelPicture;
var img = excelPicture.Image;
但是 excelPicture 变量变为空。如何从 ExcelDrawing 创建图像文件??
这似乎无法通过 EPPlus 完成 API。 GitHub project repository how export the drawings to a file. But the provided solution 中有open issue,问题不起作用(好像是@Onchomngebul 自己写的评论)
另一种解决方案是在 Spire.XLS nuget-package (or via free version FreeSpire.XLS).
中使用 Workbook
class
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);
有关详细信息,请参阅问题中的此 comment。
另一种解决方法是尝试使用Excel.ChartObject. I think this question Exporting Excel Charts as Images可能对你有帮助。
我试过了;
var excelPicture = sheet.Drawings[0] as OfficeOpenXml.Drawing.ExcelPicture;
var img = excelPicture.Image;
但是 excelPicture 变量变为空。如何从 ExcelDrawing 创建图像文件??
这似乎无法通过 EPPlus 完成 API。 GitHub project repository how export the drawings to a file. But the provided solution 中有open issue,问题不起作用(好像是@Onchomngebul 自己写的评论)
另一种解决方案是在 Spire.XLS nuget-package (or via free version FreeSpire.XLS).
中使用Workbook
class
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);
有关详细信息,请参阅问题中的此 comment。
另一种解决方法是尝试使用Excel.ChartObject. I think this question Exporting Excel Charts as Images可能对你有帮助。