Chart still bounded to first worksheet when copying a worksheet from one workbook to another workbook

Hi,

I’m having problems when copying a worksheet from one workbook to another workbook.
If I copy the worksheet a second time into the new workbook, the chart uses the data from the first worksheet.

I found this post which describes a problem similar to the one I’m having but on the .NET version of Aspose Cells:

I am attaching an archive in which there is an example file as well as the result obtained with the following code:

String excelFileName = "test_excel_vente_composants_test_graphiques.xlsx";
Workbook wb = new Workbook(excelFileName);
Workbook copyWb = new Workbook();
copyWb.getWorksheets().clear();
CopyOptions copyOptions = new CopyOptions();
copyOptions.setReferToDestinationSheet(true);
Worksheet copyWs = copyWb.getWorksheets().add("Test_1");
copyWs.copy(wb.getWorksheets().get(0), copyOptions);
copyWs = copyWb.getWorksheets().add("Test_2");
copyWs.copy(wb.getWorksheets().get(0), copyOptions);
copyWb.save(excelFileName.substring(0, excelFileName.length() - 5) + "_updated.xlsx");

tests.zip (28.1 KB)

You will see that in the “Test_2” tab, the chart data points to the “Test_1” tab.

You will also find that the print area is not correctly defined in the “Test_2” tab, while it is correct in the “Test_1” tab.

Thanks in advance for your help, regards,

Charlie

@cdelanneau,

Thanks for the template file.

Please notice, I am able to reproduce the issue as you mentioned by using your template file. I found chart is bounded to first worksheet when copying a worksheet second time from one workbook to another workbook. I noticed in the “Test_2” worksheet, the chart data points to the “Test_1” instead of “Test_2”. Moreover, I also find the print area is not correctly defined in the “Test_2” tab, while it is correct in the “Test_1” tab. I have logged a ticket with an id “CELLSJAVA-44550” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

Hi,

Thank you for your reply and the speed of your support.
Do you have any idea when the issue will be fixed?

Thanks in advance for your feedback, have a great day.

Regards,

Charlie

@cdelanneau,

The issue is in process but not fixed yet. We will check if we could provide an update or ETA on the issue. We will get back to you soon.

@cdelanneau,

Please try the following code for your reference:

Sample code:

    Workbook wb = new Workbook(excelFileName);
	Workbook copyWb = new Workbook();
	copyWb.getWorksheets().clear();
	
	CopyOptions copyOptions = new CopyOptions();
	copyOptions.setReferToDestinationSheet(true);
	Worksheet copyWs = copyWb.getWorksheets().add("Test_1");
	copyWs.copy(wb.getWorksheets().get(0), copyOptions);
	
	CopyOptions copyOptions2 = new CopyOptions();
	copyOptions.setReferToDestinationSheet(true);
	copyWs = copyWb.getWorksheets().add("Test_2");
	copyWs.copy(wb.getWorksheets().get(0), copyOptions2);
	
	copyWb.save(excelFileName.substring(0, excelFileName.length() - 5) + "_java.xlsx");

Hi,

Thanks for your feedback.

I tested with the code from your comment and it works perfectly.

Although this code solves my problem, I would like to know for my information if you consider that this operation is normal or if it is still an anomaly that you will correct in a future version?

Thanks in advance for your feedback, have a great day.

Regards,

Charlie

@cdelanneau,

Good to know that the updated code segment works fine now.

And, this is normal/expected behavior and we will not fix this issue in the APIs. You only need to instantiate and use new CopyOptions (with relevant “ReferToDestinationSheet” option on) everytime for each copy operation.

Hi,

Thanks for your feedback and your responsiveness!
That’s fine, so the topic is closed.

Have a great day.

@cdelanneau,

You are welcome.