We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Line chart copy issue


I am using Aspose Cells API (8.2.x) to copy a line chart from one sheet to another.
The copied chart is squeezed up. It is not copied as per its original size.
After analyzing, I have found that this is because of the mismatch in the cell sizes of the source sheet and target sheet.

To copy chart to another sheet, I have used code specified in this link: http://www.aspose.com/docs/display/cellsjava/Copy+Shapes+between+Worksheets

Can you please let me know what extra needs to be done so that the chart is copied in its original size to the target sheet.

For your reference I have attached the code snippet as well the excel file being used and output.

Following is the code snippet:

Workbook workbook = new Workbook(“C:/temp/LineChartRenderingIssue.xlsx”);
WorksheetCollection ws = workbook.getWorksheets();
Worksheet sheet1 = ws.get(“Sheet1”);
Chart chart = sheet1.getCharts().get(“Chart 7”);
ChartShape cshape = chart.getChartObject();

int sheetIndex = ws.add();
Worksheet worksheet = ws.get(sheetIndex);

//Setting the name of the newly added worksheet
String transientSheetName = “TransientWorksheet”;
//Copy the Chart to Second Worksheet
worksheet.getShapes().addCopy(cshape, 0, 0, 0, 0);

//Making remaining sheets invisible as the output is required for only TransientWorksheet
for (int i = 0; i < ws.getCount(); i++) {
String sheetName = ws.get(i).getName();

workbook.save(“c:/temp/Out.xlsx”, SaveFormat.XLSX);



Well, the copied chart shape is squeezed in the new sheet due to cells sizes in rows/ columns, this is expected behavior. I think you may try to add the following lines of code for your requirements.
Sample code:

//Copy the Chart to Second Worksheet
worksheet.getShapes().addCopy(cshape, 0, 0, 0, 0);

//Get the new chart and set its height and width accordingly
Chart chart1 = worksheet.getCharts().get(0);

Hope, this helps a bit.

Thank you.

Thanks. That worked.



Good to know that it figures out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.