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)