// 返回去掉空行的记录数
private static int getRightRows(Sheet sheet) {
int rsCols = sheet.getColumns(); // 列数
int rsRows = sheet.getRows(); // 行数
int nullCellNum;
int afterRows = rsRows;
for (int i = 1; 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;
}
// 返回去掉空列的记录数
private static int getRightCols(Sheet sheet) {
int rsCols = sheet.getColumns(); // 列数
int rsRows = sheet.getRows(); // 行数
int nullCellNum;
int afterCols = rsCols;
for (int i = 0; i < rsCols; i++) { // 统计列中为空的单元格数
nullCellNum = 0;
for (int j = 0; j < rsRows; j++) {
String val = sheet.getCell(i, j).getContents();
val = StringUtils.trimToEmpty(val);
if (StringUtils.isBlank(val))
nullCellNum++;
}
if (nullCellNum >= rsRows) { // 如果nullCellNum大于或等于总的行数
afterCols--; // 列数减一
}
}
return afterCols;
}