我想使用 POI 从 Excel 工作表中删除空白行。
我们有类似 shiftRow()
或 removeRow()
的方法,但它不可用
在这种情况下。请帮助我完成它。
最佳答案
请尝试以下代码。当存在多个连续的空白行时,它也适用于我。
for(int i = 0; i < sheet.getLastRowNum(); i++){
if(sheet.getRow(i)==null){
isRowEmpty=true;
sheet.shiftRows(i + 1, sheet.getLastRowNum(), -1);
i--;
continue;
}
for(int j =0; j<sheet.getRow(i).getLastCellNum();j++){
if(sheet.getRow(i).getCell(j).toString().trim().equals("")){
isRowEmpty=true;
}else {
isRowEmpty=false;
break;
}
}
if(isRowEmpty==true){
sheet.shiftRows(i + 1, sheet.getLastRowNum(), -1);
i--;
}
}
关于java - 如何使用 POI 删除工作表之间的空白行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12382024/