我用xlsx。我要删除一行。比方说第五排。这意味着第6行应该变成5,7应该变成6.
我试过了
sheet.removeRow(sheet.getRow(6));
sheet.shiftRows(6, 6, -1);但是上面的命令只删除值。留下空白细胞。但是我需要在excel中模拟delete选项。
发布于 2014-02-22 17:18:33
你能试试下面的代码吗?
public static void removeRow(HSSFSheet sheet, int rowIndex) {
int lastRowNum=sheet.getLastRowNum();
if(rowIndex>=0&&rowIndex<lastRowNum){
sheet.shiftRows(rowIndex+1,lastRowNum, -1);
}
if(rowIndex==lastRowNum){
HSSFRow removingRow=sheet.getRow(rowIndex);
if(removingRow!=null){
sheet.removeRow(removingRow);
}
}
}它将移动行,然后删除它。
https://stackoverflow.com/questions/21957561
复制相似问题