问题描述
我想读的使用阿帕奇POI一定XLSX文件中的数据(单元格值)。
下面的code成功地创建了 SXSSFWorkBook
实例,并分配db.xlsx(我的虚拟XLSX)。我试图改变表号和双与 getSheetNumber
方法检查它,以确保工作簿正确分配。
I want to read data ( cell values ) from a certain xlsx file using apachi poi.The code below creates the SXSSFWorkBook
instance successfully and assigns db.xlsx ( my dummy xlsx). I have tried changing sheet numbers and double checking it with the getSheetNumber
method to make sure the workbook is correctly assigned.
接下来我要指定特定表(指数 0
与名称主
)以 SXSSFSheet
实例,但目前它返回空
。 (我都一直 getSheetAt
和 getSheet
方法)。
Next I want to assign a specific sheet (index 0
with name main
) to SXSSFSheet
instance, but currently it returns null
. (I have both tried getSheetAt
and getSheet
methods).
SXSSFRow DummyRow;
SXSSFCell DummyCell;
int RowCount;
OPCPackage pkg = OPCPackage.open(blabla string adress);
XSSFWorkbook wb = new XSSFWorkbook(pkg);
Workbook MainBook = new SXSSFWorkbook(wb,100);
int a = MainBook.getNumberOfSheets();
SXSSFSheet MainSheet = (SXSSFSheet) MainBook.getSheetAt(0);
RowCount = MainSheet.getLastRowNum();
我在做什么错了?
What am I doing wrong?
编辑:
我曾尝试 getSheetName
方法,有一个积极的结果。所以,问题是,在工作表中达到行。所以,最后一行 getLastRowNum()
是行不通的。
I have tried getSheetName
method and had a positive result. So the problem is with reaching rows in Worksheet. so, the last line getLastRowNum()
is not working.
推荐答案
您不能。 SXSSFWorkBook是只写,它不支持读取
You can't. SXSSFWorkBook is write only, it doesn't support reading
有关的文件的.xlsx低内存读,你应该看看
For low memory reading of .xlsx files, you should look at the XSSF and SAX EventModel documentation
这篇关于与Apache POI的SXSSFSheet从读取数据的xlsx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!