Apache POI 3.10.1:您的InputStream既不是OLE2流,也不是OOXML流

时间:2014-11-23 02:06:04

标签: java excel apache apache-poi

我正在使用Apache POI 3.10.1库来读取后缀为.xlsx的Excel文件,以下是初始化该文件的工作簿的代码的一部分,但我不断收到此错误:

Your InputStream was neither an OLE2 stream, nor an OOXML stream

我的相关代码:

            File dbFile = new File("/path/to/the/excel.xlsx");
            InputStream dbInFileStream = new FileInputStream(new File(dbPath));
            org.apache.poi.ss.usermodel.Workbook workbook = null;

            try {
//              workbook = new XSSFWorkbook(dbInFileStream);  // this does not work
                workbook = WorkbookFactory.create(dbInFileStream); // this is the cause for the above error
            } catch (IOException e) {

                e.printStackTrace();
            } 
            catch(InvalidFormatException e) {
                e.printStackTrace();
            }

我尝试读取POI 3.10.1的API,似乎WorkbookFactor.create()需要一个字节码数组,但我不知道如何将输入流转换为byteArray。有人可以帮忙吗?感谢

0 个答案:

没有答案