removeRow() 只删除数据,不删除行
用
sheet.shiftRows(rowIndex+1,lastRowNum,-1);
/**
* Remove a row by its index
* @param sheet a Excel sheet
* @param rowIndex a 0 based index of removing row
*/
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);
}
}
}
参考:http://stackoverflow.com/questions/1834971/removing-a-row-from-an-excel-sheet-with-apache-poi-hssf
本文介绍了一种使用Apache POI库在Excel表格中删除指定行的方法。通过shiftRows方法实现行上移,达到删除行的效果,并针对最后一行的特殊情况进行了处理。
3192

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



