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

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

问题描述

我们使用 apache poi 3.8 来解析 excels.我们需要能够检测(并跳过)隐藏的行,因为它们在我们的用例中往往包含垃圾数据.

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())
        ...

但是对于我们得到的每一行(上面 for 循环中的自定义输出):

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()"是不起作用还是不像我想的那样起作用?还有另一种方法来检测隐藏的行吗?(隐藏的列也是一个不错的奖励,但相关性略低)

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 应该正常工作.

否则,您可以检查行的高度,因为隐藏行的高度往往设置为 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天全站免登陆