gpt4 book ai didi

java - 如何使用java获取excel中选定行的数量?

转载 作者:行者123 更新时间:2023-11-29 04:56:04 25 4
gpt4 key购买 nike

我想使用 Java 获取列出设备 ID 的选定行的数量,忽略空白单元格。我正在使用 Apache POI 处理用于 selenium 自动化的 excel 表。

计数应从第 3 行(即 LV431408)开始到第 17 行(即 A9N26924)。

我使用了 sheet.getPhysicalNumberofRows() 但它考虑了空白单元格。

请引用附件中的屏幕截图。

enter image description here

最佳答案

您应该使用下面的代码来获取总行排除空白。

int count = 0;
for (Row row : sheet) {
for (Cell cell : row) {
if (cell.getCellType() != Cell.CELL_TYPE_BLANK) {
if (cell.getCellType() != Cell.CELL_TYPE_STRING ||
cell.getStringCellValue().trim().length() > 0) {
count++;
break;
}
}
}
}

关于java - 如何使用java获取excel中选定行的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33731861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com