jxls阅读excel与未知的行数

如何configurationjxls API来读取Excel表格,在编译时我不知道行号。

什么是loopbreakcondition。

无法findExcel表中有多less行有有效的数据,并在那里读取。

有什么select?

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

您可以指定一个空值作为循环中断条件

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

这将循环,直到在最后一个有效的传递之后的下一行( cellcheck中的offset=0 )中find一个空单元格作为第一个单元格( cellcheck上的offset=0 )。 您可以使用offset属性来更改单元格或行不能为空。

一个rowcheck元素可以包含任意数量的cellcheck元素。 在我的情况下,inputExcel中的单元格都不是强制性的,所以我为行中的每个单元格指定了一个空白的单元格cellcheck元素。

示例(假设连续有3个单元格)

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

含义:

如果下一行中的所有单元都为空,则停止循环。

在这种情况下,您可能需要某些单元格不为空白,您可以通过仅包含所需单元格来简化上述中断条件。

示例(假设一行中有3个单元,最后一个单元是强制的)

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

含义:

如果下一行中的第三个单元格为空,则停止循环。

使用此链接http://www.mail-archive.com/jxls-user@lists.sourceforge.net/msg00094.html

基本上你只需要定义光标的开始位置。

  <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> 

这将读取第7行中的所有logging,直到达到环路中断条件。endRow值在这里稍微有些混乱,但是循环中断由loopbreakcondition而不是endRow值来pipe理。