如何使用POI SXSSF读取大型电子表格 [英] How to use POI SXSSF to read a large spreadsheet

查看:160
本文介绍了如何使用POI SXSSF读取大型电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SXSSF读取xls文件.我已经阅读了有关SXSSF的信息,但并不清楚确切地如何使用它.所以我遇到了一些问题.

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.

有人可以用Java代码帮助我读取大型xls文件(大约100,000行和7-8张纸)吗?

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

(从评论中编辑)

这是我尝试过的:

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); 
    } 
 } 

推荐答案

SXSSF仅用于写入大型excel文件(xlsx),而不用于读取.

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

要读取较大的excel文件,请在以下网址参考基于Apache POI的SAX解析的事件处理API: https://poi.apache.org/components/spreadsheet/how-to. html .

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/examples/xssf/eventusermodel/XLSX2CSV.java

这篇关于如何使用POI SXSSF读取大型电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆