我需要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; read 0x0000000000000000, expected 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();
}
});
}