使用Apache POI检测隐藏的单元格在Excel中 [英] Detecting hidden cells in excel using apache poi

查看:1625
本文介绍了使用Apache POI检测隐藏的单元格在Excel中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用Apache POI 3.8解析过人之处。我们需要能够检测(并跳过)隐藏的行,因为他们往往​​包含在我们的用例的垃圾数据。

We are using apache poi 3.8 to parse excels. We need to be able to detect (and skip) hidden rows as they tend to contain junk data in our usecases.

这似乎可以这样:

row.isFormatted() && row.getRowStyle().getHidden()

但从来没有出现任何的行级格式化(getRowStyle()始终返回null)。作为最后的手段,我们认为检查单元格样式可能的工作:

But there never appears to be any row-level formatting (getRowStyle() always returns null). As a last resort we thought checking cell styles might work:

for (int i = 0; i < row.getLastCellNum(); i++) {
    Cell cell = row.getCell(i);
    if (cell != null && cell.getCellStyle() != null && cell.getCellStyle().getHidden())
        ...

但是,对于每行,我们得到(在上述的自定义输出为环路):

But for every row we get (custom output in the above for loop):

Cell 0 is not hidden org.apache.poi.hssf.usermodel.HSSFCellStyle@1b9142d0 / false

请问getHidden()不能正常工作或因为我认为它它不工作?有另一种方法来检测隐藏的行? (隐藏的列也将是一个不错的奖金,但稍显不足有关ATM)

Does the "getHidden()" not work or does it not work as I think it does? Is there another way to detect hidden rows? (hidden columns would also be a nice bonus but slightly less relevant atm)

推荐答案

getRowStyle ,你应该应该正常工作。

getRowStyle should normally work as you supposed.

否则,您可以检查该行的高度,隐藏的行往往有一个高度设置为0。
使用 row.getHeight() row.getZeroHeight()

Otherwise, you can check the height of the row, as hidden rows tends to have a height set to 0. Using row.getHeight() or row.getZeroHeight().

这篇关于使用Apache POI检测隐藏的单元格在Excel中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆