Reading jxls excel with unknown row count

How to configure jxls API to read excel sheet where I won’t know the number of lines at compile time.

what will be the loopbreak condition.

Cant jxls will find out how many rows in the excel sheet have valid data and read up.

What are the alternatives?

link [http://jxls.sourceforge.net/reference/reader.html] [1]

+4
source share
2 answers

You can specify an empty value as a condition for terminating a loop

<loopbreakcondition> <rowcheck offset="0"> <cellcheck offset="0"></cellcheck> </rowcheck> </loopbreakcondition> 

This will loop until it finds an empty cell as the first cell ( offset=0 on cellcheck ) in the next row ( offset=0 on rowcheck ) after the last valid pass. You can use the offset attributes to change which cell or row cannot be empty.

Element

A rowcheck can contain any number of cellcheck elements. In my case, none of the cells in the input Excel was required, so I specified an empty cellcheck element for each cell in the row.

Example (suppose there are 3 cells in a row)

  <loopbreakcondition> <rowcheck offset="0"> <cellcheck offset="0"></cellcheck> <cellcheck offset="1"></cellcheck> <cellcheck offset="2"></cellcheck> </rowcheck> </loopbreakcondition> 

Value:

Stop the loop if all cells in the next row are empty.

In the event that some cells must not be empty, you can simplify the above interruption condition by including only the necessary cells.

Example (it is assumed that there are 3 cells in the cell, and the last cell is required)

  <loopbreakcondition> <rowcheck offset="0"> <cellcheck offset="2"></cellcheck> </rowcheck> </loopbreakcondition> 

Value:

Stop cycle if the third cell in the next row is empty.

+2
source

Use this link http://www.mail-archive.com/ jxls-user@lists.sourceforge.net /msg00094.html

Basically you should only determine the start position of the cursor.

  <loop startRow="7" endRow="7" items="department.staff" var="employee" varType="net.sf.jxls.sample.model.Employee"> <section startRow="7" endRow="7"> <mapping row="7" col="0">employee.name</mapping> <mapping row="7" col="1">employee.age</mapping> <mapping row="7" col="3">employee.payment</mapping> <mapping row="7" col="4">employee.bonus</mapping> </section> <loopbreakcondition> <rowcheck offset="0"> <cellcheck offset="0">Employee Payment Totals:</cellcheck> </rowcheck> </loopbreakcondition> </loop> 

This will read all the records from line 7 until the loop condition is reached. The endRow value is a little confused here, but the loop break is determined by the loopbreakcondition condition, not the endRow value.

0
source

Source: https://habr.com/ru/post/1369175/


All Articles