Home » excel » c# – EPPlus and graphics

c# – EPPlus and graphics

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m creating a spreadsheet with EPPlus library on a .NET 4.0 command line application.

I successfully loaded all the data from the data base, at the end I’m creating a graphic, this is my code:

var chart = sheet.Drawings.AddChart("Revenue", OfficeOpenXml.Drawing.Chart.eChartType.ColumnClustered);

chart.SetPosition(2, 0, 4, 0);
chart.SetSize(650, 400);

chart.Series.Add(ExcelRange.GetAddress(3, 2, 14, 2),ExcelRange.GetAddress(3, 1, 14, 1));
chart.Title.Text = "Revenue";

I open the generated file in MS Office 2010 and everything looks fine, the data the graphic, etc.. but if I open the same generated file in OpenOffice 3.3 the graphics are empty.

The weird thing is, if I open the file in Office 2010 and make a copy (Save As).. and I open the copy in OpenOffice, the graphics are good… so I’m wondering if I’m missing something in my code to make it compatible with both Office2010 and OpenOffice

Thanks for the help!

How to&Answers:

It appears that when EPPlus creates the chart, it only stores the cell references for the data series. It doesn’t actually store the value of each data point.

Microsoft Excel will recalculate the value of each data point (I believe), possibly ignoring any data point cache in the spreadsheet file.

OpenOffice/LibreOffice appears to read only the cached data point values in the chart section. This is why the chart doesn’t appear in OpenOffice, because there are no data point values written via EPPlus.