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

Free Support Forum - aspose.com

OutOfMemory when converting from spreadsheet to JPG

Hi,

Our system throws OutOfMemoryError at converting an Excel file to JPG when creating the new instance of SheetRender. please see the attached zip to reproduce this issue. The sample spreadsheet is 24k only, however the conversion task could not finish with 8g memory and cause hang CPU as well.

Feel free to contact us if you need further information.

Regards,

Feng Xu
aspose-excel.zip (21.8 KB)

@atlassian

Thanks for using Aspose APIs.

If the file size is small, it does not mean, it will not take lots of memory. Please open your Excel file and press Ctrl+End and you will go to last cell i.e. XEV1047853. It means, there are lots and lots of pages inside your worksheet.

Please see this screenshot, it shows there are more than 35,000,000 pages inside your first worksheet. So it will definitely throw out of memory exception. One way to get rid of it is to delete all blank columns and blank rows using

  • Worksheet.getCells().deleteBlankColumns()
  • Worksheet.getCells().deleteBlankRows()

Screenshot:

Hi Shakeel,

Thanks for the quick reply.

If I understand correctly, the call to Worksheet.getCells().deleteBlankColumns() / deleteBlankRows() might have side effect to the original file.

Is there an API that could check the cell numbers without loading all into memory?

@atlassian

Please use the MaxDisplayRange property. Please see the following sample code and its console output

Java

Workbook wb = new Workbook(dirPath + "crash.xlsx");

Worksheet ws = wb.getWorksheets().get(0);

Range rng = ws.getCells().getMaxDisplayRange();

System.out.println(rng.getRefersTo());

Console Output
=Tabelle1!$A$1:$XEV$1047853

@atlassian,

We have looked into this issue further. Since, there are so many blank pages, so you should use

ImageOrPrintOptions.setPrintingPage(PrintingPageType.IGNORE_BLANK)

and then it will reduce your pages to 42 pages and you will be able to get rid of out of memory exception. Please see the following code for your help

Java

Workbook wb = new Workbook(dirPath + "crash.xlsx");

Worksheet ws = wb.getWorksheets().get(0);

ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.setPrintingPage(PrintingPageType.IGNORE_BLANK);
opts.setImageFormat(ImageFormat.getJpeg());
//opts.OnePagePerSheet = true;
            
SheetRender sr = new SheetRender(ws, opts);
System.out.println("Pages Count: " + sr.getPageCount());
sr.toImage(0, dirPath + "sheetImage.jpg");

Console Output
Pages Count: 42