Copying charts

Hi

If i have an excelworkbook (.xlsx) containg a chart formatted with a theme, and i copy the chart to another workbook using Copy function on the Worksheet. If i then save the workbook and look at the result in Excel the chart copied has the correct theme, however if i use the ToImage function on the copied chart, it shows the default colors (blue/purple), if i do the same (ToImage) on the original chart it shows the themed chart.

I am presuming i am missing some settings or something else that needs to be copied, but can't find what, can someone please help?

Many thanks,

DJ

Hi,


Could you try our latest version/fix: v7.0.3.2. If you still find the issue, kindly do paste your runnable sample code with your template files, we will check your issue soon. Also, attach your output image generated by Aspose.Cells API.

Thank you.

Hi Amjad,

Thanks for replying, i have downloaded the latest version using the link provided, but it does not make a difference, below the code used and attached are the files:

1. Book1.xlsx template file
2. Book2.xlsx output file with chart that looks like the chart in book1
3. image.png the output image file.

            Workbook wb1 = new Workbook("Book1.xlsx");
            Workbook wb2 = new Workbook();
            Worksheet sh = wb1.Worksheets["Sheet1"];
            wb2.Worksheets.Add();
            wb2.Worksheets[0].Copy(sh);
        sh = wb1.Worksheets["Chart1"];
        wb2.Worksheets.Add();
        Int32 i = 1;
        wb2.Worksheets[i].Copy(sh);
        Aspose.Cells.Charts.Chart ch = wb2.Worksheets[i].Charts[0];
        ch.NSeries.Clear();
        ch.NSeries.Add("Sheet1!B2:C3", false);
        ch.NSeries.CategoryData = "Sheet1!B1:C1";
        ch.Style = sh.Charts[0].Style;
        for (int j = 0; j < ch.NSeries.Count; j++)
        {
            ch.NSeries[j].Name = "=Sheet1!" + CellsHelper.CellIndexToName(1 + j, 0);
        }
        wb2.Save("Book2.xlsx");
        wb2.Worksheets[1].Charts[0].ToImage("image.png");

Hi,

Thanks for your sample file and the code. I was able to reproduce this issue using the latest version:
Aspose.Cells for .NET v7.0.3.2

We have logged this issue in our database. We will look into it and fix it and update you asap.

This issue has been logged as CELLSNET-40128.

Hi there, thanks for letting me know, is there any indication on how long it normally takes for these sorts of issues to be fixed?

Many thanks,

Dj

Hi,


We are working on the issue, it is not fixed yet. If the issue is not very complex, it should be fixed within a few days e.g (before the end of this week or so). If it is complex, it might take some time. Anyways, if this is complex issue, we will let you know the eta for it here.

Thank you.

Hi,

Please try the fixed version: v7.0.3.3. Your issue should be fixed in it now.


Thank you.

Hi there,

Thanks for the quick response, I have tested it and the issue is indeed resolved.

Great service, thanks.

Dj

The issues you have found earlier (filed as CELLSNET-40128) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hello @Amjad_Sahi

Is their any way in asposecells using which we can copy format, title or setting of charts from one excel file to another excel file.

I am asking this because when i am removing border of chartarea and plotarea by using below code it is also removing title of the graph(chart) also changing some settings of charts.

my code
chart = worksheets.get(i).getCharts().get(j)
chart.getPlotArea().getBorder().setVisible(False)
chart.getChartArea().getBorder().setVisible(False)

Thanks .

@asposeLegit,

There is no single API to copy formatting or setting to the charts. You may get formatting, settings and data of the chart and its objects from one workbook and apply to other chart in other workbook yourselves via relevant lines of code.

@asposeLegit,
Maybe you can refer to the following documents:

@asposeLegit
Hope, this helps a bit. If you still find the issue, kindly do paste your runnable sample code with your template files, we will check your issue soon.

Hello @xinyazhu

My code is

from openpyxl import *
import jpype
jpype.startJVM()
from asposecells.api import *
import asposecells

wb = Workbook(“input file location”)
worksheets = wb.getWorksheets()
wscount = worksheets.getCount()
#print(flow_variables[‘Output Location’])

print(wscount)

for i in range(0,wscount):
chartsheet = worksheets.get(i).getCharts().getCount()

if (chartsheet > 0):
	for j in range(0, chartsheet):
		chart = worksheets.get(i).getCharts().get(j)
		chart.getPlotArea().getBorder().setVisible(False)
		chart.getChartArea().getBorder().setVisible(False)
	wb.save("saving file location")
else:
	pass

wb.save(“saving output file location”)

jpype.shutdownJVM()

In above code, first i am checking if charts is present or not on excel sheet if chart is present then we are removing border of that chart and saving that excel file. But when i am removing border and saving that file then it changing some format of chart or sometime it removing chart title or sometime just changing formatting of title.

Thanks.

hello @Amjad_Sahi

How can we do this like, can you give me some link of documentation of asposecells so that i can go through for my guidance.

Thanks.

@asposeLegit
Hi, we created a sample excel file then I ran the same code which works fine in our side samplefiles.7z (41.2 KB)
, so please share your template files, Thanks!