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!