Exception occurs when saving a Excel file into HTML format

Hi there

I am using Aspose Cells 17.5 to convert Excel file into HTML format.

Here is my code for test:

String fileName = “59_.xlsx”;

Workbook book = new Workbook(“custom/input/xlsx/” + fileName);
ByteArrayOutputStream baos = new ByteArrayOutputStream();

File dir = new File(“custom/output/xlsx/” + fileName + “/”);
dir.mkdirs();

for (int page = 0; page < book.getWorksheets().getCount(); page++) {

for (int i = 0; i < book.getWorksheets().getCount(); i++) {
book.getWorksheets().get(i).setVisible(true);
}

for (int i = 0; i < book.getWorksheets().getCount(); i++) {
// only one page for test
if (i != page) {
book.getWorksheets().get(i).setVisible(false);
}
}
HtmlSaveOptions saveOps = new HtmlSaveOptions();
saveOps.setClearData(false);
saveOps.setCreateDirectory(false);
saveOps.setExportActiveWorksheetOnly(false);
saveOps.setExportHiddenWorksheet(false);
saveOps.setParseHtmlTagInCell(true);
saveOps.setEncoding(Encoding.getUTF8());
saveOps.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.REMOVE);
saveOps.setHiddenColDisplayType(HtmlHiddenColDisplayType.REMOVE);
saveOps.setExportImagesAsBase64(true);

saveOps.setStreamProvider(new IStreamProvider() {

  @Override
  public void initStream(StreamProviderOptions arg0) throws Exception {
  	arg0.setStream(new ByteArrayOutputStream());
  }

  @Override
  public void closeStream(StreamProviderOptions arg0) throws Exception {
  	System.out.println(arg0.getDefaultPath());
  	OutputStream stream = arg0.getStream();
  	if (stream instanceof ByteArrayOutputStream) {
  		ByteArrayOutputStream bb = (ByteArrayOutputStream) stream;
  		IOUtils.write(bb.toByteArray(),
  				new FileOutputStream("custom/output/xlsx/" + arg0.getDefaultPath()));
  	}
  }

});
book.save(baos, saveOps);
IOUtils.write(baos.toByteArray(),
new FileOutputStream(“custom/output/xlsx/” + fileName + “/” + page + “.html”));
}

An NullPointerException will be thrown from internal of the library with a Excel file like this:

 java.lang.NullPointerException
	at com.aspose.cells.zra.a(Unknown Source)
	at com.aspose.cells.zamk.a(Unknown Source)
	at com.aspose.cells.zamk.b(Unknown Source)
	at com.aspose.cells.Font.getColor(Unknown Source)
	at com.aspose.cells.zafj.a(Unknown Source)
	at com.aspose.cells.zafj.b(Unknown Source)
	at com.aspose.cells.zafj.a(Unknown Source)
	at com.aspose.cells.zafi.c(Unknown Source)
	at com.aspose.cells.zafi.a(Unknown Source)
	at com.aspose.cells.zafn.a(Unknown Source)
	at com.aspose.cells.Workbook.a(Unknown Source)
	at com.aspose.cells.Workbook.save(Unknown Source)

This Exception occurs with Cells 17.1.0 and above.
And I tried 16.12.0, there is no Exception thrown.

I have uploaded the Excel file.
Please check this issue, thank you~

Craig

59_.zip (374.1 KB)

P.S. I suggest that it should be allowed to upload Excel files directly in the forum.(.xlsx file extension is banned)

@craig.w.su

Thanks for using Aspose APIs.

Such issues are being fixed by Aspose Website Team, please spare us some time. Hopefully, these issues will be fixed soon.


We were able to observe this issue and logged it in our database for investigation and for a fix. Once, the issue is resolved or we have some other news for you, we will let you know asap.

This issue has been logged as

  • CELLSJAVA-42357 - Exception occurs when saving an Excel file into HTML format

Java

Workbook wb = new Workbook(dirPath + "59_.xlsx");
wb.save(dirPath + "out.html");

@craig.w.su,

This is to inform you that we have fixed your issue “CELLSJAVA-42357” now. We will soon provide you the fix after performing QA and incorporating other enhancements and fixes.

Thank you

@craig.w.su,

Please try the latest version/fix: Aspose.Cells for Java v17.7.7:

Your issue should be fixed in it.

Let us know your feedback.

Thank you.

@Amjad_Sahi

I checked this issue, and it is fixed.
Thanks for your help

Craig

@craig.w.su

Thanks for your feedback and using Aspose.Cells.

It is good to know that your issue is resolved with the latest fix. Let us know if you encounter any other issue, we will be glad to look into it and help you further.

The issues you have found earlier (filed as CELLSJAVA-42357) have been fixed in Aspose.Cells for Java 17.8.