Search code examples
c#libreofficeopenoffice-calcepplus-4

Charts created by EPPlus 4.1 library in .xlsx format are not displaying in openoffice or libreoffice


Charts created by EPplus in C# is not displaying in LibreOffice and OpenOffice, but they are displayed properly in Microsoft office.

There is one workaround, if i open the excel file in microsoft office and then save it again that file charts are visible properly on Libreoffice and OpenOffice.

Charts displayed in Microsoft office as shown in below picture: open in Microsoft excel viewer

Charts displayed in LibreOffice and OpenOffice as shown in below picture. OpenOffice image

Is there any property that i need to set while saving the charts using EPPlus so that it can be viewed in OpenOffice.


Solution

  • I had this problem too and had to do compare the generated files with saved files and look through the source code to find out how to do it:

    For a line chart:

    ExcelLineChartSerie serie = (ExcelLineChartSerie)chart.Series.Add(...);
    serie.Marker = eMarkerStyle.None;
    serie.LineColor = Color.FromArgb( 0x00, 0x45, 0x86 );
    

    For a bar chart:

    ExcelChartSerie serie = chart.Series.Add(...);
    serie.Fill.Style = eFillStyle.SolidFill;
    serie.Fill.Color = Color.FromArgb( 0x00, 0x45, 0x86 );
    

    I haven't used other charts yet so there may be some other fields to be initialized.

    Update:

    I saw that my charts also had no axes and had to find out how to convince libreoffice to draw them:

    chart.XAxis.Border.Fill.Style = eFillStyle.SolidFill;
    chart.XAxis.Border.Fill.Color = Color.FromArgb( 0x00, 0x00, 0x00 );
    chart.YAxis.Border.Fill.Style = eFillStyle.SolidFill;
    chart.YAxis.Border.Fill.Color = Color.FromArgb( 0x00, 0x00, 0x00 );