Page 1 of 1
Issue of the SaveChartAsImage function

Posted:
Wed Jul 14, 2021 5:42 am
by flyenter
After I prepared the raw data, I want to refresh the related chart and save it as image.
Following is my functional code:
Workbook wb = new Workbook();
wb.LoadFromFile(finalFileName, ExcelVersion.Version2016);
//Following code doesn't work, if I only call the SaveToFile function, the chart won't be refreshed.
//Worksheet ws = wb.Worksheets[0];
//ws.Copy(ws.Range["A2:B2"], ws.Range["A3:B3"], true);
//XlsPivotTable pt = wb.Worksheets[0].PivotTables[0] as XlsPivotTable;
//pt.Cache.IsRefreshOnLoad = true;
//wb.SaveToFile("working//final.xlsx", ExcelVersion.Version2016);
//After I called the SaveAsImage, and call RefreshChart again, the Chart will be refreshed correctly.
wb.SaveAsImage(0, 100, 100);
foreach (Worksheet ws2 in wb.Worksheets)
{
for (int iIndex = 0; iIndex < ws2.Charts.Count; iIndex++)
{
Chart ct = ws2.Charts[iIndex];
ct.RefreshChart();
Image img = wb.SaveChartAsImage(ws2, iIndex);
img.Save($"working//{ws2.Name}-{ct.Name}.png", System.Drawing.Imaging.ImageFormat.Png);
}
}
wb.Dispose();
Following the code above, I can export the image for each chart. But part of the format of the chart image is mess.
I have uploaded the template and image files. and I use the FreeSpire.XLS 10.10.0 version.
Could you help me to solve the problem, thanks!
Re: Issue of the SaveChartAsImage function

Posted:
Wed Jul 14, 2021 9:21 am
by rachel.lei
Hello,
Thanks for your inquiry.
I tested your case with both FreeSpire.XLS 10.10.0 and the latest commercial version (
Spire.XLS Pack(Hotfix) Version:11.7.0), I indeed noticed that the generated image was not correct. I have logged this issue in our bug tracking system with the ticket SPIREXLS-3344.
If there is any update, we will let you know. Sorry for the inconvenience caused.
Sincerely,
Rachel
E-iceblue support team
Re: Issue of the SaveChartAsImage function

Posted:
Wed Jul 14, 2021 10:15 am
by flyenter
Thanks for your quick response.
I have tried to add 2 chart sheets which based on the different row data sheet within same excel file.
and try to export the chart as image. but I just got one correct image, and another one is incorrect. (looks like the data doesn't be refreshed.)
After I removed the correct chart sheet, and run the project again. the previous incorrect chart can be saved as image correctly.
While I recover to the previous 2 chart sheets case, the issue reappeared.
Could you help us on the issue?
Thanks!
Re: Issue of the SaveChartAsImage function

Posted:
Thu Jul 15, 2021 3:03 am
by rachel.lei
Hello,
Thanks for your reply.
I did an initial test but did not encounter the issue you mentioned. To help us investigate further, please provide your input file and your full test code. Thanks in advance.
Sincerely,
Rachel
E-iceblue support team
Re: Issue of the SaveChartAsImage function

Posted:
Fri Jul 16, 2021 2:14 am
by flyenter
I have uploaded the example case. please pay attention on the CopyImage.png and PaySummary-chtSummary.png, the charts couldn't reflected the data volume.
Re: Issue of the SaveChartAsImage function

Posted:
Fri Jul 16, 2021 10:15 am
by rachel.lei
Hello,
Thanks for your sharing.
I have reproduced your issue and logged it in our bug tracking system with the ticket SPIREXLS-3359. If there is any update, we will let you know. Sorry for the inconvenience caused.
Sincerely,
Rachel
E-iceblue support team
Re: Issue of the SaveChartAsImage function

Posted:
Thu Jul 29, 2021 3:20 am
by flyenter
Hi,
Do you have the estimated time for the issue fix?
Re: Issue of the SaveChartAsImage function

Posted:
Thu Jul 29, 2021 6:10 am
by rachel.lei
Hello,
Thanks for your inquiry.
I checked the status of your issues but found that they have not been resolved. Sorry we are unable to give you an estimated time at present. Please spare us more time.
We will keep you informed if there is any update. Sorry for the inconvenience caused.
Sincerely,
Rachel
E-iceblue support team
Re: Issue of the SaveChartAsImage function

Posted:
Tue Sep 14, 2021 10:15 am
by rachel.lei
Hello,
Thanks for your patience.
Glad to inform you that we just released Spire.XLS Pack(Hotfix) Version:11.9.2, which fixes the issues SPIREXLS-3344 and SPIREXLS-3359. Kindly note that for both issues, you need to call the method "wb.CalculateAllValue();" to recalculate the formula values before converting.
Website download link:
https://www.e-iceblue.com/Download/down ... t-now.htmlNuGet download link:
https://www.nuget.org/packages/Spire.XLS/11.9.2Code:
- Code: Select all
//#SPIREXLS-3344
//...
wb.CalculateAllValue();
pt.CalculateData();
//...
//#SPIREXLS-3359
//...
wb.CalculateAllValue();
foreach (Worksheet wkSheet in wb.Worksheets)
{
for (int iIndex = 0; iIndex < wkSheet.Charts.Count; iIndex++)
{
Chart ct = wkSheet.Charts[iIndex]; ct.PivotTable.CalculateData();//计算关联透视表
ct.RefreshChart();
Image img = wb.SaveChartAsImage(wkSheet, iIndex);
img.Save($"working//{wkSheet.Name}-{ ct.Name}.png", System.Drawing.Imaging.ImageFormat.Png);
}
}
//...
Sincerely,
Rachel
E-iceblue support team