Free Support Forum -

Aspose cell not exporting shape text from chart


I am using aspose cell 19.1.0 in dotnet core 2.1 application.
I have excel file which has got one chart sheet. The chart has textbox on primary & secondary Y axis (value axis). They are displayed correctly when opened in MS Excel, but when exported to image using aspose cell, chart is exported but those textboxes text are not exported.

Below is the sample code. Those textboxes have formula based text, ie it is reading text from some other cell’s text in another worksheet.

This is not happening with all excel files, it is only happening with certain files only. I am not sure why this is happening.

If i iterate shape collection in chart, i could see textbox has got valid text value (Shape.Text), but when it is saved in image, those text is not passed.

Is there a way, i can refresh shape text? i used caculateformula on sheet and workbook, but it does not help.

string file2 = @“c:\a.xlsx”;
Workbook workbook2 = new Workbook(file2);
var chartSheet2 = workbook2.Worksheets[“ChartSheet”];

        ImageOrPrintOptions opt1 = new ImageOrPrintOptions()
            ImageType = ImageType.Png,

var fileToSave1 = @“C:\test.png”;
chartSheet.Charts[0].ToImage(fileToSave1, opt1);



Thanks for providing us some details.

Well, Chart.ToImage() would only render chart to image file format. I guess since those shapes(i.e., textboxes) are not part of chart object, so such shapes would be missed. You should try to use Sheet to Image feature to export your desired area (i.e., Chart with shapes) to image format. You may set printable area before rendering the underlying sheet to image, see the following lines of code for your reference:
Sample code:

Worksheet worksheet = workbook.Worksheets[0];
            //You may specify it dynamically
            string printArea = string.Format("A1:E4");
            worksheet.PageSetup.PrintArea = printArea;


Thanks Amjad for prompt response. Shapes are already part of chart, because i could see in chart[0].shapes collection.

Also for if i open excel file in MS excel and then just press enter in text box formula bar and simply save and close, then Aspose cell is exporting image correctly with those shapes texts also. This is weird, i am not sure what is happening in this case.

Also if i do shape.ToImage, it generates blank image for that shape. But if i open excel file in MS excel and then just press enter in text box formula bar, save and close, then run shape.ToImage, it will extract correct text from shape into image.

Most important, in all cases, chart[0].shapes have valid text in textbox shapes, it just that they are not imported into image.



Thanks for providing further details.

Could you try to call ShapeCollection.UpdateSelectedValue() method after updating the underlyng values for those shapes and before rendering to image file format if it makes any difference.
Sample code:


If you still find the issue, kindly do provide us your template file, we will check it soon.