Reading data from xlsx using Apache POI SXSSFSheet

I want to read data (cell values) from a specific xlsx file using apachi poi. The code below creates the SXSSFWorkBook instance successfully and assigns db.xlsx (my dummy xlsx). I tried changing the sheet numbers and double checking it with the getSheetNumber method to make sure the book is correctly assigned.

Next, I want to assign a specific sheet (index 0 with the name main ) to the SXSSFSheet instance, but currently it returns null . (I tried the getSheetAt and getSheet ).

 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 tried the getSheetName method and had a positive result. Therefore, the problem is reaching the lines in the worksheet. so the last line of getLastRowNum() does not work.

+7
java apache xlsx apache-poi
source share
1 answer

You can not. SXSSFWorkBook is written only, it does not support reading

To read low-memory .xlsx files, you should look at the XSSF and SAX EventModel documentation

+14
source share

All Articles