How to use POI SXSSF to read a large spreadsheet

℡╲_俬逩灬. 提交于 2019-12-04 11:14:52

问题


I am trying to read an xls file by using SXSSF. I have read about SXSSF, but do not understandexactly how to use it. So I am running into some problems.

Can anybody help me with the java code for reading large xls files (some 100,000 rows and 7-8 sheets).

(Edit from the comments)

Here is what I have tried:

Workbook workBook = new SXSSFWorkbook(200); 
workBook = WorkbookFactory.create(inputStream); 
Sheet sheet = workBook.getSheetAt(0); 
int totalRows = sheet.getPhysicalNumberOfRows(); 

for (int i=0; i<totalRows; i++) { 
    Row row = sheet.getRow(i); 
    int totalCols = row.getPhysicalNumberOfCells(); 
    for(int j=0; j<totalCols; j++) { 
        Cell cell = row.getCell(j); 
    } 
 } 

回答1:


SXSSF is only to write large excel files (xlsx) and not to read.

To read large excel files, please refer to SAX parsing based event handling API of Apache POI at: https://poi.apache.org/components/spreadsheet/how-to.html.

A very good working example is present at: https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java



来源:https://stackoverflow.com/questions/10053421/how-to-use-poi-sxssf-to-read-a-large-spreadsheet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!