Couldn't convert the third sheet of the XLSX file

Hi guys,
I couldn’t convert the third sheet of the attached XLSX file
Please assist
please 1234.xlsx.zip (894 Bytes)
Thanksfile.zip (7.2 KB)

bug.zip (7.6 KB)

@berzh,

Thanks for the archive containing image files and some details.

Please provide your source Excel file which you are converting. Also paste your sample code (runnable), we will check it soon.

@Amjad_Sahi
Here is archive with all data

bug.zip (7.6 KB)

@berzh,

Thanks for the template file and sample code.

Well, the first three sheets are blank, there is nothing to print (you may try to take the print preview in MS Excel manually and you will get the error message), so when you render to image file for these sheets, you will get an image file with “0” bytes. If you still want to render those blank sheets, you may try to add a line of code to your code segment, see the code segment for your reference:
e.g
Sample code:

try ( final InputStream inputStream = new FileInputStream(“1234.xlsx”) ) {
final Workbook workbook = new Workbook(inputStream);
final int pageCount = workbook.getWorksheets().getCount();
for ( int page = 0; page < pageCount; page++ ) {
try ( final OutputStream outputStream = new FileOutputStream(“f:\Files\” + page + “.png”) ) {
final ImageOrPrintOptions options = new ImageOrPrintOptions();
options.setImageFormat(getPng());
options.setOnePagePerSheet(true);
options.setQuality(resolution);
options.setOutputBlankPageWhenNothingToPrint(true);
final Worksheet worksheet = workbook.getWorksheets().get(page);
final SheetRender render = new SheetRender(worksheet, options);
render.toImage(0, outputStream);
}
}
}

Hope, this helps a bit.

Thanks for the hint! I’ve tried to upgrade the Aspose Cells dependency from 17.4.0 to 17.9, and now I can use setOutputBlankPageWhenNothingToPrint as you’re suggesting. However, if I convert the following zipped XLSX file 123.zip (7.2 KB) whose last page is empty but filled orange, 2.png is rendered as a blank white page. Is it working by design? Thanks!

@user33,

Well, this is tricky situation. The ImageOrPrintOptions.setOutputBlankPageWhenNothingToPrint(true) would simply render white blank page for a page which is empty (no matter if it has formatted range). If you try to take the print preview of the third sheet, you will get error that there is nothing to be printed. To cope with your situation (if you still want to render blank formatted (with shading color) page), you may try to add blank string (" ") into a cell. See the updated code segment for your reference:
e.g
Sample code:


for ( int page = 0; page < pageCount; page++ ) {
try ( final OutputStream outputStream = new FileOutputStream(“f:\Files\” + page + “.png”) ) {
final ImageOrPrintOptions options = new ImageOrPrintOptions();
options.setImageFormat(getPng());
options.setOnePagePerSheet(true);
options.setQuality(resolution);
options.setOutputBlankPageWhenNothingToPrint(true);
final Worksheet worksheet = workbook.getWorksheets().get(page);
CellArea[] areas = worksheet.getPrintingPageBreaks(options);
// System.out.println(areas.length);
if(areas.length==0)
{
worksheet.getCells().get(“I51”).putValue(" ");
}
final SheetRender render = new SheetRender(worksheet, options);
render.toImage(0, outputStream);
}
}
}

Hope, this helps a bit.

That’s a great workaround! Thanks!