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.
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.
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();
System.out.println(chart.getHeightPercent());
System.out.println(chart.getChartArea().getWidth());
int sheetIndex = ws.add();
Worksheet worksheet = ws.get(sheetIndex);
//Setting the name of the newly added worksheet
String transientSheetName = “TransientWorksheet”;
worksheet.setName(transientSheetName);
//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();
if(!transientSheetName.equalsIgnoreCase(sheetName)){
ws.get(i).setVisible(false);
}
}
workbook.save(“c:/temp/Out.xlsx”, SaveFormat.XLSX);