java – jxls读取excel,其中包含未知行数

我如何配置jxls API来读取Excel工作表,在编译时我不知道行的数量.

什么是loopbreak条件.

不能找出excel表中有多少行有效数据,并在那里读取.

有哪些替代方案?

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

最佳答案 您可以指定空值作为循环中断条件

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

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

rowcheck元素可以包含任意数量的cellcheck元素.在我的情况下,输入Excel中的所有单元格都不是必需的,因此我为行中的每个单元格指定了一个空白的单元格检查元素.

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

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

含义:

Stop looping if all of the cells in the next row are empty.

如果您需要一些单元格不是空白,您可以通过仅包含所需的单元格来简化上述中断条件.

示例(假设连续有3个单元格,最后一个单元格是必需的)

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

含义:

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

点赞