Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Fri Dec 10, 2021 10:50 am

When exporting chart as image from a workbook or to a file,

the format of the element inside the cart are not correctly converted.

See workboot and saved images

Windows 10 64 bits
Locale FR
Attachments
save_chart_issues.zip
(67.92 KiB) Downloaded 120 times

QuentinSup
 
Posts: 46
Joined: Mon Oct 18, 2021 9:18 am

Mon Dec 13, 2021 6:28 am

Hello,

After investigation, we found that the chart in the Excel file you provided is of 2D type, but the data series is set to 3D format, so the chart looks like 3D. Currently, our product does not support maintaining this format when saving the chart as a picture. Anyway, I have submitted this feature to our Dev team. However, this function cannot be realized in a short time. Once it is achieved in the future, I will inform you in time.
In addition, if you want the result file to retain the 3D format, you need to set the Chart type to the corresponding 3D type, as shown in the following code. But for the "CombinationChart" type of Chart, Microsoft Excel does not support the combination of 3D types. Our Spire.XLS follows the rules of Microsoft Excel, which does not support 3D type combinations.
Code: Select all
chart.setChartType(ExcelChartType.Column3DClustered)

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Mon Dec 13, 2021 2:24 pm

Thanks for your reply,

As user of the Spire.XLS lib, I attend that the saveChartAsImage have the same result that a save as from the XLS workbook, but is not.

But it is not only a question of 3D format. The font is not applied correctly (see PNG exports)

QuentinSup
 
Posts: 46
Joined: Mon Oct 18, 2021 9:18 am

Tue Dec 14, 2021 1:58 am

Hello,

Thank you for your feedback.
Does "see PNG exports" refer to the image you provided in the previous post? If it is, I carefully compared the image and the chart( in the source file), and found that the font size in the image is different from the source file. If it is not, please share the pictures here.
In addition, kindly note that our Spire.XLS needs to read the font information from the system when converting Excel to pictures. In order to ensure that the converted image uses the same font as the Excel file, please make sure that the fonts used in the excel file are installed on your system

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Tue Dec 14, 2021 3:56 pm

The labels of the data points from the series into the chart do not have the fonts assigned with this code :

If you open the workbook, the font is Calibri excepted for the data point labels...

Code: Select all
 for (int i = 0; i < s.getPointNumber(); i++) {
                final ChartDataPoint dp = s.getDataPoints().get(i);
                dp.getDataLabels().setPosition(DataLabelPositionType.Automatic);
                if (data.getFontName() != null && !data.getFontName().isBlank()) {
                    dp.getDataLabels().setFontName(data.getFontName());
                }
}

QuentinSup
 
Posts: 46
Joined: Mon Oct 18, 2021 9:18 am

Wed Dec 15, 2021 8:04 am

Hello,

Thank you for your feedback.
I tested the code you provided and found that the data label font setting was unsuccessful. After investigation, I found that the font setting of the data label should use the series setting, please refer to the following code.
Code: Select all
Workbook workbook = new Workbook();
workbook.loadFromFile("dd0287fe-3894-4ebe-8b20-388293077842_charts.xlsx");
 ExcelFont font = workbook.createFont();
 font.setFontName("Calibri");
 for (int j = 1; j < workbook.getWorksheets().getCount();j++){
     Chart chart = workbook.getWorksheets().get(j).getCharts().get(0);
     for (int i = 0; i < chart.getSeries().getCount();i++){
         ChartSerie s = chart.getSeries().get(i);
         s.getDataPoints().getDefaultDataPoint().getDataLabels().getTextArea().setFont(font);
     }
 }

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS