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

Free Support Forum - aspose.com

An error is reported when the spreadsheet is converted to PNG format

An error is reported when the spreadsheet is converted to PNG format
image.png (53.5 KB)

the error is:

at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:75)
at java.awt.image.Raster.createPackedRaster(Raster.java:467)

this is my code:

Workbook workbook = new Workbook("D://Aspose//SMS_36139//SMS_36139.xlsx");
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.setImageFormat(ImageFormat.getPng());
options.setOnlyArea(true);
options.setOnePagePerSheet(true);
options.setTransparent(true);
SheetRender render = new SheetRender(workbook.getWorksheets().get(0), options);
render.toImage(0, "D://Aspose//SMS_36139//output/SMS_36139.png");

this is my excelSMS_36139.zip (3.9 MB)

@xhaixia,

Thanks for the template file and screenshot.

Please notice, I am able to reproduce the issue as you mentioned by using your template file. The error might be occurred and due to the fact that you are using OnePagePerSheet option and trying to render single page based on so many pages in the worksheet. Anyways, we need to evaluate the issue in details. We have logged a ticket with an id “CELLSJAVA-44387” for your issue.

Once we have an update on it, we will let you know.

@xhaixia

Because there are too many pages in sheet, if you set OnePagePerSheet in this case, the dimensions of the image will be very large. It will break at java BufferedImage initialization: new BufferedImage(width, height).

Please don’t set OnePagePerSheet if there are too many pages.

Code:

Workbook workbook = new Workbook("D://Aspose//SMS_36139//SMS_36139.xlsx");
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.setImageType(ImageType.PNG);
options.setOnlyArea(true);
//options.setOnePagePerSheet(true);
options.setTransparent(true);

//the fastest way to get evaluated pages in the sheet
SheetPrintingPreview sheetPrintingPreview = new SheetPrintingPreview(workbook.getWorksheets().get(0), options);

//don't set OnePagePerSheet if there are too many pages, the threshold is depended on your environment.
if(sheetPrintingPreview.getEvaluatedPageCount() < 100)
{
    options.setOnePagePerSheet(true);
}
SheetRender render = new SheetRender(workbook.getWorksheets().get(0), options);
render.toImage(0, "D://Aspose//SMS_36139//output/SMS_36139.png");