Hello,
Please see the attached input and output files. The output file is generated with this code block. When image is taken of the chart named “ScreenShot”, the DataLabels in the chart are changed into a bad state. To see the issue open the output.xlsx file and notice that the data label on the first bar is “50.0%”. Now save the document and watch the data label change to “-50.0% - 40.0%”. Looking at the XML spec it appears that the DataLabels are changing from a cell range reference to a static text value and all of the columns worth of data label are being placed into the first column. This adverse behavior only occurs after using the ToImage method on the Chart.
var workbook = new Workbook("input.xlsx");
workbook.Worksheets[0].Charts["ScreenShot"]
.ToImage(new MemoryStream(), new ImageOrPrintOptions()
{
ChartImageType = ImageFormat.Png,
ImageType = Aspose.Cells.Drawing.ImageType.Png,
Transparent = true
});
workbook.Save("output.xlsx", SaveFormat.Xlsx);
I opened your input.xlsx file into MS Excel 2013 and 2016 and both versions show that data labels are: “-50.0% - 40.0%”, see the screenshot attached. sc_shot1.png (33.1 KB)
So, it is not an issue in the output XLSX file as both input and output files display same data labels.
I believe if you use CalculateFormula before saving the output file then it’ll save like this too. That’s what happens in our product. We determined that this state only exists if we take an image of the chart.
I still could not find the issue. I opened the output file (generated by the code with your input file). I found no difference at all. I used MS Excel 2016 to open the file into it, see the screenshot attached. sc_shot12.png (28.6 KB)
Did you open the output file into MS Excel 2013 or 2016 and what is the result? Which MS Excel vision you are using?
I did test your scenario/case again using your input.xlsx file with the following code. Please note, I am using our latest version of Aspose.Cells for .NET v22.3, please try it if you are not already using it.
e.g. Sample code:
var workbook = new Workbook("e:\\test2\\input.xlsx");
workbook.Worksheets[0].Charts["ScreenShot"]
.ToImage(new MemoryStream(), new ImageOrPrintOptions()
{
ChartImageType = ImageFormat.Png,
ImageType = Aspose.Cells.Drawing.ImageType.Png,
Transparent = true
});
workbook.Save("e:\\test2\\output.xlsx", SaveFormat.Xlsx);
Please find attached the output file generated on my end. I opened it into MS Excel 2007, 2013, 2016 and Excel 365. All versions show data labels fine. Please open the output XLSX (attached in the archive) into MS Excel on your end and let us know the results with some screenshots. files1.zip (24.2 KB)
We were using version .21 which exhibited the problem. I can confirm it’s working correctly with version 22.3. Next time we’ll test in the latest version first. I’ll confirm with the customer that this is working properly in the latest version and will report back.
Good to know that your issue is sorted out by the new version/fix. Feel free to write us back if you have further queries or comments, we will be happy to assist you soon.