Hi,
I am using aspose-cells-8.3.2.jar.
On converting a pie chart to image or pdf, I get a blank output.
Kindly treat this issue on urgent basis as this has come from the customer’s production environment.
Code snippet for image:
chart.toImage(outputFile.getAbsolutePath(),getImageOrPrintOptions(ExcelDataObjectTypes.CHART, outputFormatProperties, true, false));
Code snippet for PDF
private File chartToPdf(Workbook workbook, com.aspose.cells.Chart chart, NameValue[] outputFormatProperties) throws IOException,Exception {
WorksheetCollection ws = workbook.getWorksheets();
ChartShape cshape = chart.getChartObject();
int sheetIndex = ws.add();
com.aspose.cells.Worksheet worksheet = ws.get(sheetIndex);
worksheet.getCells().setStandardWidth(1);
//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);
//Get the new chart and set its height and width accordingly
com.aspose.cells.Chart chart1 = worksheet.getCharts().get(0);
chart1.getChartArea().setHeight(cshape.getHeight());
chart1.getChartObject().setWidth(cshape.getWidth());
//Make remaining worksheets invisible so that they are not part of the output pdf
for (int i = 0; i < ws.getCount(); i++) {
String sheetName = ws.get(i).getName();
if(!transientSheetName.equalsIgnoreCase(sheetName)){
ws.get(i).setVisible(false);
}
}
PdfSaveOptions pdfSaveOptions = getPdfSaveOptions();
worksheet.getPageSetup().setTopMargin(pdfOutputTopMargin);
worksheet.getPageSetup().setBottomMargin(pdfOutputBottomMargin);
worksheet.getPageSetup().setRightMargin(pdfOutputRightMargin);
worksheet.getPageSetup().setLeftMargin(pdfOutputLeftMargin);
// Save the workbook
File outputPdfFile = OfficeResourceUtility.createTemporaryFile(".pdf");
workbook.save(outputPdfFile.getAbsolutePath(), pdfSaveOptions);
workbook.save(“c:\temp\test.xlsx”, SaveFormat.XLSX);
return outputPdfFile;
}
I tried with the attached excel file.
Sheetname : charts & tables
Problematic Charts : Chart 1, Chart 2
Problematic Charts : Chart 1, Chart 2
Same behavior works fine when done from within the MS Excel.
Can you please help me with this issue.
Thanks,
Jaspreet