private static int getRightRows(Sheet sheet) {
int rsCols = sheet.getColumns(); // 列数
int rsRows = sheet.getRows(); // 行数
int nullCellNum;
int afterRows = rsRows;
for (int i = 2; i < rsRows; i++) { // 统计行中为空的单元格数
nullCellNum = 0;
for (int j = 0; j < rsCols; j++) {
String val = sheet.getCell(j, i).getContents();//获取单元格内容
val = StringUtils.trimToEmpty(val);
if (StringUtils.isBlank(val))//判断单元格是否为空计算空单元格的数量
nullCellNum++;
}
if (nullCellNum >= rsCols) { // 如果nullCellNum大于或等于总的列数
afterRows--; // 行数减一
}
}
return afterRows;
}
jxl导入EXCEL获取真实行数,去除空白行
最新推荐文章于 2025-03-12 14:31:08 发布
本文介绍了一种使用Excel API处理表格数据的方法,通过遍历行和列来统计空单元格数量,以此确定有效的行数。这种方法有助于提高数据清洗的效率。

2807

被折叠的 条评论
为什么被折叠?



