apache poi的xlsx文件过程给出异常

时间:2019-03-24 15:12:36

标签: java spring-boot apache-poi

我正在使用apache poi读取Excel文件并对其进行处理。

这就是我正在做的高水平

CloseableHttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet("http://file-examples.com/wp-content/uploads/2017/02/file_example_XLSX_10.xlsx");
HttpResponse response = client.execute(request); 
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();  
Workbook wb = WorkbookFactory.create(inputStream);

但是当create被调用时,我遇到了异常

java.lang.IllegalArgumentException: InputStream of class class org.apache.commons.compress.archivers.zip.ZipArchiveInputStream is not implementing InputStreamStatistics.
    at org.apache.poi.openxml4j.util.ZipArchiveThresholdInputStream.<init>(ZipArchiveThresholdInputStream.java:63)

这仅适用于xlsx文件。以下是poi jar中的create方法外观

public static Workbook create(InputStream inp, String password) throws IOException, EncryptedDocumentException {
        InputStream is = FileMagic.prepareToCheckMagic(inp);
        FileMagic fm = FileMagic.valueOf(is);

        switch (fm) {
            case OLE2:
                POIFSFileSystem fs = new POIFSFileSystem(is);
                return create(fs, password);
            case OOXML:
                return createXSSFWorkbook(is);
            default:
                throw new IOException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
        }
    }

在xlsx中进入createXSSFWorkbook

但是我用一个示例Java项目测试了相同的场景,它正在工作。此异常仅与其他项目一起出现,该项目是带有undertow的spring boot项目。像poi和commons.compress这两个项目的依赖关系是相同的。我不知道为什么它仅在该项目中给出此异常

0 个答案:

没有答案