Hello,
I have a problem with some graphics when I copy a worksheet from a workbook to a new workbook.
The line charts are not rendered with the right colours. This only seems to happen with line charts in my case but maybe other types of charts have this problem too.
I have attached the template I used to reproduce the anomaly (named “test_aspose_3.xlsx”) and the files generated from this template (named “test_aspose_3_company_data.xlsx”, “test_aspose_3_global_results. xlsx” and “test_aspose_3_comparison.xlsx”) in which the line charts do not have the right colours (you can see that in the last file named “test_aspose_3_comparison.xlsx” there is no colour problem on the bar chart).
test_aspose_3.zip (162.5 KB)
And the code I used to generate these files below:
String excelFileName = "test_aspose_3.xlsx";
Workbook wb = new Workbook(excelFileName);
for (int i = 0; i < wb.getWorksheets().getCount(); i++) {
Worksheet ws = wb.getWorksheets().get(i);
CopyOptions copyOptions = new CopyOptions();
copyOptions.setReferToDestinationSheet(true);
copyOptions.setCopyInvalidFormulasAsValues(true);
Workbook copyWb = new Workbook();
Worksheet copyWs = copyWb.getWorksheets().get(0);
copyWs.setName(ws.getName());
copyWs.copy(ws, copyOptions);
copyWb.save(excelFileName.substring(0, excelFileName.length() - 5) + "_" + ws.getName() + ".xlsx");
}
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 when copying a worksheet from a workbook to a new workbook, the line charts are not rendered with the right colors, other charts are rendered fine though. I have logged a ticket with an id “CELLSJAVA-45022” for your issue. We will look into it soon.
Once we have an update on it, we will let you know.
1 Like
@cdelanneau
Hi, since the source workbook including charts which has its own theme, so you need to copy the theme to your "copyWb ", please refer to the following code which works fine in our side. Thanks!
String excelFileName = "test_aspose_3.xlsx";
Workbook wb = new Workbook(excelFileName);
for (int i = 0; i < wb.getWorksheets().getCount(); i++) {
Worksheet ws = wb.getWorksheets().get(i);
CopyOptions copyOptions = new CopyOptions();
copyOptions.setReferToDestinationSheet(true);
copyOptions.setCopyInvalidFormulasAsValues(true);
Workbook copyWb = new Workbook();
copyWb.copyTheme(wb);
copyWb.setDefaultStyle(wb.getDefaultStyle());
Worksheet copyWs = copyWb.getWorksheets().get(0);
copyWs.setName(ws.getName());
copyWs.copy(ws, copyOptions);
copyWb.save(excelFileName.substring(0, excelFileName.length() - 5) + "_" + ws.getName() + ".xlsx");
}
Hope, this helps a bit.
Hi,
Thank you for providing the solution. It looks like it is working correctly on our end.
I wish you a merry Christmas and a happy new year!
@cdelanneau,
Good to know that the suggested code segment works for your need well. We have closed the ticket. Feel free to write us back if you have further queries or issue, we will be happy to assist you soon.
Merry Christmas and Happy New Year! Wishing you the very best!