-2

I'm working with apache poi and now I have the following trouble. I'm including apache poi in my project in this way:

<dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.7</version>
</dependency>

Now my problem is that I'm not able to get a correct number of rows, for example I have two files (Source file and UploadFile). The uploadFile is made select all in the Source file and paste all in the uploadFile. In that case the following snippet of code print 65535

XSSFSheet firstSheet =  (XSSFSheet) wbUploaded.getSheetAt((short)0); //Foglio Luce
 System.out.println(firstSheet .getLastRowNum());

//Read the sheet
for(Row row : sheetLuce){
        //Do something
}

Also if my file is the following:

enter image description here

I understood that the problem depends from the way to make the file, why if I instead to select,copy and paste all, I select (on Source file) only the filled row and I copy them in the upload filethe number of rows is printed correctly. Now I want to ask you like poi manage the number of rows?

Skizzo
  • 2,883
  • 8
  • 52
  • 99

2 Answers2

0

the API is not like that you use. you may try the answers in the question below to get the last row.

Finding the last row in an Excel spreadsheet

Community
  • 1
  • 1
paco alcacer
  • 381
  • 2
  • 13
0

By default an excel sheet contains 65535 rows. As does yours. So the result of that method is correct. Its not clear why you want that number but if you want to stop the loop based on that you could stop the for loop when you encounter a row that is empty.

Juru
  • 1,623
  • 17
  • 43