0%

poi使用Iterator跳过空白单元格

poi使用Iterator跳过空白单元格

1
2
3
4
5
6
7
//这种情况下。每遇到空白格,cellIterator.next()跳过空白格,取空白格后面一个有内容的单元格。
//就好像空白格不存在一样
Row row = getRow();
Iterator<Cell> cellIterator = row.iterator();
while(cellIterator.hasNext()){
Cell cell = cellIterator.next();
}

不使用迭代器,不会跳过空白单元格了。只不过获取到的空白单元格为NULL。
得到最后单元格个数。使用for循环,一个一个拿。

1
2
3
4
5
6
7
8
9
Row row = getRow();
int n = row.getLastCellNum();
for(int i = 0;i<n;i++){
//你给我个null,是不是给我找麻烦。
Cell cell = row.getCell(i);
if(cell==null){
//处理空白单元格
}
}

————————————————
版权声明:本文为CSDN博主「mr_O-O」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/DHPSL/java/article/details/82418823

Donate comment here.

欢迎关注我的其它发布渠道