monitorjbl / excel-streaming-reader

An easy-to-use implementation of a streaming Excel reader using Apache POI
Apache License 2.0
953 stars 344 forks source link

Error when loading xlsx file in Spring #80

Closed ghost closed 7 years ago

ghost commented 7 years ago

I use the latest version.

My code:

private void testExcel(String fileName) {
        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(classLoader.getResource(fileName).getFile());
        Workbook workbook = StreamingReader.builder()
                .rowCacheSize(100)    // number of rows to keep in memory (defaults to 10)
                .bufferSize(4096)     // buffer size to use when reading InputStream to file (defaults to 1024)
                .open(file);
    }

Error Logs:

java.lang.NoClassDefFoundError: org/apache/poi/POIXMLTypeLoader
    at org.openxmlformats.schemas.spreadsheetml.x2006.main.SstDocument$Factory.parse(Unknown Source)
    at org.apache.poi.xssf.model.SharedStringsTable.readFrom(SharedStringsTable.java:119)
    at org.apache.poi.xssf.model.SharedStringsTable.<init>(SharedStringsTable.java:106)
    at org.apache.poi.xssf.eventusermodel.XSSFReader.getSharedStringsTable(XSSFReader.java:82)
    at com.monitorjbl.xlsx.impl.StreamingWorkbookReader.init(StreamingWorkbookReader.java:117)
    at com.monitorjbl.xlsx.StreamingReader$Builder.open(StreamingReader.java:278)
monitorjbl commented 7 years ago

This looks like a classpath problem to me. If I had to guess, you've got some conflicting versions of POI in there. The current version of the library needs POI 3.13.