我需要文件excel来转换Workbook
(apache poi)。我得到InputStream
:
InputStream in = getInputStream(); // from user file.xls
if(in != null){
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(in); //exception
}
但接下来我得到了例外:
org.apache.poi.poifs.filesystem.NotOLE2FileException:无效的标头签名;读取 0x0005060000100809,预期为 0xE11AB1A1E011CFD0 - 您的文件似乎不是有效的 OLE2 文档
我从文件中获得的 InputStream 是构建 Apachi Poi
和问题NotOLE2FileException: Invalid header signature; 读取 0x0000000000000000,预期 0xE11AB1A1E011CFD0 对我不起作用
我使用 Vaadin 框架。
MultiFileMemoryBuffer buffer = new MultiFileMemoryBuffer();
Upload upload = new Upload(buffer);
upload.setAcceptedFileTypes("application/vnd.ms-excel");
upload.setMaxFiles(1);
upload.setSizeFull();
upload.addSucceededListener((event) -> {
name = event.getFileName();
try (InputStream inputStream = buffer.getInputStream(name) // getInputStream
) {
Workbook workbook = WorkbookFactory.create(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
});
}