Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

java - Reading data from xlsx with Apache POI's SXSSFSheet

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.

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?

Edit:

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can't. SXSSFWorkBook is write only, it doesn't support reading

For low memory reading of .xlsx files, you should look at the XSSF and SAX EventModel documentation


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...