10

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.

1 Answer 1

20

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.