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.

Tue Dec 15, 2020 7:51 am

Good morning.

I haven't found anything on how to copy a chart to the clipboard directly through the library. Do you know if this option exists?

Thank you

blastdoman
 
Posts: 27
Joined: Thu Jul 02, 2020 7:06 am

Tue Dec 15, 2020 11:06 am

Hello,

Thanks for your inquiry.
You want to copy chart from one sheet to another, right? Below is the corresponding code for your reference. But unfortunately, when using the latest Spire.XLS Pack(Hotfix) Version:10.12.0, the application will throw the error error"Object reference not set to an instance of an object" when calling the Clone method. This issue has been logged in our bug tracking system with the ticket SPIREXLS-3023. We will let you know if there is any update.
Code: Select all
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("ChartSample.xlsx");
            Worksheet sheet = workbook.Worksheets[0];

            Chart chartEmpty = workbook.Worksheets[1].Charts.Add();
            Chart srcChart = workbook.Worksheets[0].Charts[0];
            workbook.Worksheets[1].Charts.Add(srcChart.Clone(chartEmpty.Parent));

            workbook.SaveToFile("result.xlsx");


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Tue Dec 15, 2020 11:32 am

Hi Rachel.

Initially I wanted to copy a chart to the clipboard (just like doing Ctrl + Copy). As I have not found how to do it, my second option was to save the charts to disk as images using the "SaveChartAsImage" method and then copy them, but I found the problem I describe here https://www.e-iceblue.com/forum/savechartasimage-method-problems-t9817.html. So I thought, let's copy all the charts in the first tab and that's it, but then I found the problem described here https://www.e-iceblue.com/forum/how-to-copy-a-chart-t2092.html.

In short, it has been a set of chained problems.

Thank you very much for the interest. I'll keep you posted.

Greetings.

blastdoman
 
Posts: 27
Joined: Thu Jul 02, 2020 7:06 am

Wed Dec 16, 2020 1:42 am

Hello,

Thanks for your prompt response.
Regarding copying a chart to the clipboard (just like doing Ctrl + Copy), sorry our Spire.XLS does not support this feature.

As for the "SaveChartAsImage" method, as I mentioned in this post, I did an initial test but did not reproduce your issue. Attached is my input file that all charts can be saved successfully, you can give it a try.

Meanwhile, I will keep you informed if there is any update on SPIREXLS-3023.

Sincerely,
Rachel
E-iceblue support team
Attachments
InputFile.zip
(83.35 KiB) Downloaded 137 times
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Mon Feb 08, 2021 9:40 am

Hello,

Hope you are doing well.
Glad to inform that we just released Spire.XLS Pack(Hotfix) Version:11.2.3 which fixed the issue SPIREXLS-3023, please download it from the following links and refer to the code below to test.
Website link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget link: https://www.nuget.org/packages/Spire.XLS/11.2.3

Code: Select all
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("ChartSample1.xlsx");
            Chart srcChart = workbook.Worksheets[0].Charts[0];
            workbook.Worksheets[1].Charts.Add(srcChart.Clone(workbook.Worksheets[1]));
            workbook.SaveToFile("result.xlsx");


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Sat Feb 20, 2021 1:43 am

Hello,

Hope you are doing well.
Does the hotfix work for you? Thanks in advance for your feedabck!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.XLS