jxls reading excel with unknown no of rows
How do i configure jxls API to read an excel sheet , where i will not know the no of rows at compile time.
what will be the loopbreakcondition.
Cant jxls find out how many rows in the excel sheet have valid data , and read uptill there.
What are the alternatives ?
reference [htt开发者_如何学JAVAp://jxls.sourceforge.net/reference/reader.html][1]
You can specify a blank value as the loop break condition
<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 what cell or row cannot be blank.
A rowcheck
element can contain any number of cellcheck
elements. In my case none of the cells in the input Excel were mandatory, so I specified a blank cellcheck
element for each cell in the row.
Example (assuming 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>
Meaning:
Stop looping if all of the cells in the next row are empty.
In the case you would have some cells required to be not blank, you could simplify the above break condition by only including the required cells.
Example (assuming there are 3 cells in a row and the last cell is mandatory)
<loopbreakcondition>
<rowcheck offset="0">
<cellcheck offset="2"></cellcheck>
</rowcheck>
</loopbreakcondition>
Meaning:
Stop looping if the third cell in the next row is empty.
Use this link http://www.mail-archive.com/jxls-user@lists.sourceforge.net/msg00094.html
Basically you have to define the cursor begin position only ..
<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 records from row 7 untill the loopbreak condition is reached.The endRow value is slightly confusing here but the loop break is governed by loopbreakcondition and not by endRow value.
精彩评论