Hi,
I am evaluating the Aspose.Cell java api. I would like to copy a workbook with chart to another workbook. I tried following code to accomplish it. But destination workbook does not contain the chat present in the source workbook.
Workbook workbook = new Workbook();
Worksheets worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.getSheet(0);
Cells cells = sheet.getCells();
Cell cell = cells.getCell(“A1”);
cell.setValue(“North”);
cell = cells.getCell(“A2”);
cell. setValue (“West”);
cell = cells.getCell(“A3”);
cell.setValue(“South”);
cell = cells.getCell(“B1”);
cell.setValue(4);
cell = cells.getCell(“B2”);
cell.setValue(20);
cell = cells.getCell(“B3”);
cell.setValue(50);
Charts charts = sheet.getCharts();
int index = charts.add(ChartType.COLUMN_CLUSTERED,5,0,15,5);
Chart chart = charts.getChart(index);
NSeries serieses = chart.getNSeries();
serieses.add(“A1:B3”, true);
workbook.save(“H:\temp\CopyingOfChartAspose1.xls”,FileFormatType.EXCEL2000);
Workbook source = new Workbook();
source.open(“H:\temp\CopyingOfChartAspose1.xls”,FileFormatType.EXCEL2000);
Workbook destination = new Workbook();
destination.copy(source);
destination.save(“H:\temp\CopyingOfChartAspose2.xls”,FileFormatType.EXCEL2000);
Hi,
Thank you for considering Aspose.
Well, I have tested your scenario and it works fine with the latest version of Aspose.Cells. I think you are using some old version of Aspose.Cells for Java. Please try the attached latest version and modify your code as under,
Workbook workbook = new Workbook();
Worksheets worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.getSheet(0);
Cells cells = sheet.getCells();
Cell cell = cells.getCell("A1");
cell.setValue("North");
cell = cells.getCell("A2");
cell. setValue ("West");
cell = cells.getCell("A3");
cell.setValue("South");
cell = cells.getCell("B1");
cell.setValue(4);
cell = cells.getCell("B2");
cell.setValue(20);
cell = cells.getCell("B3");
cell.setValue(50);
Charts charts = sheet.getCharts();
Chart chart = charts.addChart(ChartType.COLUMN_CLUSTERED,5,0,15,5);
NSeries serieses = chart.getNSeries();
serieses.add("A1:B3", true);
workbook.save("H:\\temp\\CopyingOfChartAspose1.xls",FileFormatType.EXCEL2000);
Workbook source = new Workbook();
source.open("H:\\temp\\CopyingOfChartAspose1.xls",FileFormatType.EXCEL2000);
Workbook destination = new Workbook();
destination.copy(source);
destination.save("H:\\temp\\CopyingOfChartAspose2.xls",FileFormatType.EXCEL2000);
Thank You & Best Regards,
Thanks. It worked with this jar.