Chart ChangeTemplate

Hi All,
Little question.
I am discovering Aspose and I try to use the function changeTemplate

So I have a pie chart.
In excel I select a custom template. (Another Pie chart with a different style).
I am doing this with a right click on the chart and “Change Chart Type” and I go to “Templates”
The new template selected is applied without any issues.

In Aspose, I get the existing chart from Excel with its chartIndex.
And I apply just the same template than previously in Excel with this line of code:
chart.ChangeTemplate(chartTemplateData);
the chart is blank.

In debug I can see that the categoriesData in chart.NSeries are set to null (after the call to the ChangeTemplate function)

Same thing the chart.NSeries.InnerList seems to be modified.
So I have a blank chart as output due to the fact the series and categoriesData are lost.

Do you know why ?
Do I have to fill again the series when I apply a chart Template ?

Thanks

@hormancey,

The ChangeTemplate method of Chart requires data (in byte array) of the chart template file (in .crtx file format – a CRTX file contains a chart template that can be applied, it stores settings for colors, axes, gridlines, categories, legends, text, title, and other chart options).

How do you specify chart template data using the method? Could you please share sample (runnable) code and sample files to evaluate your issue on our end. We will check it soon.

Hi @amjad.sahi,

This is an example of code c#:

Blockquote
var pathWorkbook = “C:\Users\hormancey\Downloads\ChartToModify.xlsx”;
var pathTemplate = “C:\Users\hormancey\AppData\Roaming\Microsoft\Templates\Charts\TestAsposeTemplate.crtx”;
var wbtest = new Workbook(pathWorkbook);
Worksheet sheettest = wbtest.Worksheets[0];
Chart charttest = sheettest.Charts[0];
// Convert the string to byte[]
byte[] chartTemplateData = File.ReadAllBytes(pathTemplate);
charttest.ChangeTemplate(chartTemplateData);
wbtest.Save(pathWorkbook);

Please find attached the chartToModify.xslx and the TestAsposeTemplate.crtx. TestAsposeTemplate.zip (14.2 KB)

As you can see if you run the code. The workbook is blank at the end tthe categoriesData in chart.NSeries are set to null. Series[0] seems modified too.

Thanks,

@hormancey
Through testing with sample files and code, we can reproduce the issue. Template replacement failed after calling the Chart.ChangeTemplate method.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-54385

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thanks @John.He
Will you post an update on this support forum or should I have to follow the ticket provided ?
If yes how to follow this ticket.
Thanks

@hormancey,

Yes, once we have an update on it, or we figure your issue out, we will inform you here.
You may follow up and ask for an update here and we will provide latest updates on the issue.

1 Like

Hi @hormancey
After repair, using your code and templates, now we can generate the following file. It will take effect in the next version(23.11). It will be released in early November.
231018.zip (13.3 KB)

Good news ! Thanks a lot !!

@hormancey,

You are welcome.

The issues you have found earlier (filed as CELLSNET-54385) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi