Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Jan 27, 2022 11:08 am

Hi,

In Excel I can easily switch between different styles of charts.
I would like to prepare a chart with custom styling and I would want to apply the style or copy it on my other charts.

Is there any way I can achieve this in code?

dangraal
 
Posts: 2
Joined: Thu Jan 27, 2022 11:05 am

Fri Jan 28, 2022 6:42 am

Hello,

Thanks for your inquiry!

Please refer to the following code to copy the chart from one sheet to another sheet.
Code: Select all
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("E:\\testdoc\\cusExcelStyle.xlsx");
            Chart chart = workbook.Worksheets["Sheet1"].Charts[0];

            Workbook newWork = new Workbook();
            Worksheet sheet = newWork.Worksheets[0];
            sheet.Charts.Add(chart.Clone(sheet));
            Chart chart2 = sheet.Charts[0];


If you encounter any other question, just feel free to contact us.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Fri Jan 28, 2022 8:06 am

I don't want to clone entire chart.

I would like to copy only the style of it.
I have data on my chart and when I change the DataRange it also changes the style of it which I don't want.

I would like to have chart generated in code and apply the style of other chart without modyfing the data or similiar solution suitable for me.

dangraal
 
Posts: 2
Joined: Thu Jan 27, 2022 11:05 am

Fri Jan 28, 2022 10:11 am

Hello,

Sorry that our Spire.Xls does not support applying the system style or custom style to the chart, or get the style from a chart which has custom style yet. I have added this feature to our upgrade list. If there is any progress, we will keep you informed. Sorry for the inconvenience caused.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.XLS