I’m using the Aspose.Cells Java API to capture an image of a Pivot Table in an excel spreadsheet. The resulting image does not retain the color and style of the original pivot table. Why would that happen?
Here is the code I’m using:
PivotTableCollection pivotTables = worksheet.getPivotTables();
Iterator<PivotTable> it = pivotTables.iterator();
while (it.hasNext()) {
PivotTable pivotTable = it.next();
System.out.println("doSnapshotByName() :: " + pivotTable.getName());
CellArea pivotArea = pivotTable.getTableRange1();
System.out.println("doSnapshotByName() :: pivot table area :: " + pivotArea);
if (request.getElementName().equalsIgnoreCase(pivotTable.getName())) {
System.out.println("doSnapshotByName() :: found pivot table :: " + pivotTable.getName());
worksheet.getPageSetup().setPrintArea(buildPrintArea(pivotArea));
worksheet.getPageSetup().setLeftMargin(0.0);
worksheet.getPageSetup().setRightMargin(0.0);
worksheet.getPageSetup().setTopMargin(0.0);
worksheet.getPageSetup().setBottomMargin(0.0);
if (request.getImageOutputFilePath().contains(".emf"))
options.setImageFormat(ImageFormat.getEmf());
else
options.setImageFormat(ImageFormat.getPng());
SheetRender sr = new SheetRender(worksheet, options);
sr.toImage(0, request.getImageOutputFilePath());
}
}