获取POI中特定行中填充的单元格数

时间:2016-05-13 14:36:16

标签: java apache-poi

请告知有没有办法让我说如果我得到一行Object作为s参数,我知道现在该行内的行号我想跟踪为该特定行提交的单元格数量。

让我们说如果行中的行号现在是67,那么只有2个单元格被填充,或者可能发生4个单元格最后填充值我想要的是填充为i的单元格的数量必须实现一些基于计数的逻辑

下面是我获取行对象的方法,在此方法中我需要获取单元格数

public  boolean isCountOfCellsFilledForARow(Row row1) {
        for (int c = row1.getFirstCellNum(); c < row1.getLastCellNum(); c++) 
{

}

}

2 个答案:

答案 0 :(得分:2)

As far as I understand you would like to find non-empty cells of the row. There is already an answered question regarding finding empty cells via apache-poi. You can use one of the provided answers to check if the cell is empty or not.

答案 1 :(得分:0)

你可以试试这个

public long countCells(Row r) {
  long count = 0;
  for(Cell c : r) {
    if (!c.toString().equals("")) {
      count++;
    }
  }
  return count;
}