Read large Excel file .xlsx

后端 未结 2 1935
别那么骄傲
别那么骄傲 2021-01-28 08:39

i\'m using library

org.apache.poi 


XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream);

I\'m trying

org.xml.sax


        
相关标签:
2条回答
  • 2021-01-28 08:58
    InputStream is = new FileInputStream(new File("yourXLSX file path"));
    Workbook workbook = StreamingReader.builder().rowCacheSize(100).bufferSize(4096).open(is))
    for (Sheet sheet: workbook) {
        //System.out.println(sheet.getSheetName());
        for (Row r: sheet) {
            for (Cell c: r) {
                //System.out.println(c.getStringCellValue());
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-28 09:20

    If the input data is too large for the available memory, you have two options.

    a) Provide more memory via the -Xmx java command line option

    b) Use the Streaming-API of POI.

    Option a) will be easy to do if the files eventually fit in memory. If the file is too large for the available physical memory, you will need to take a look at the streaming options, especially the sample XLSX2CSV shows how you can read data from arbitrarily large .xlsx files, albeit with some features that need to access multiple cells not available out of the box.

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