XSSFWorkbook takes a lot of time to load

后端 未结 2 1924
南笙
南笙 2020-12-05 21:46

I am using the following code:

File file = new File(\"abc.xlsx\");
InputStream st = new FileInputStream(file);
XSSFWorkbook wb = new XSSFWorkbook(st);


        
相关标签:
2条回答
  • 2020-12-05 21:51

    First up, don't load a XSSFWorkbook from an InputStream when you have a file! Using an InputStream requires buffering of everything into memory, which eats up space and takes time. Since you don't need to do that buffering, don't!

    If you're running with the latest nightly builds of POI, then it's very easy. Your code becomes:

    File file = new File("C:\\D\\Data Book.xlsx");
    OPCPackage opcPackage = OPCPackage.open(file);
    XSSFWorkbook workbook = new XSSFWorkbook(opcPackage);
    

    Otherwise, it's very similar:

    File file = new File("C:\\D\\Data Book.xlsx");
    OPCPackage opcPackage = OPCPackage.open(file.getAbsolutePath());
    XSSFWorkbook workbook = new XSSFWorkbook(opcPackage);
    
    0 讨论(0)
  • 2020-12-05 22:05

    Consider using the Streaming version of POI. This will load a subset of the file into memory as needed. It is the recommended method when dealing with large files.

    POI SXSSF

    0 讨论(0)
提交回复
热议问题