LD is tigger forever,CG are not brothers forever, throw the pot and shine forever.
Modesty is not false, solid is not naive, treacherous but not deceitful, stay with good people, and stay away from poor people.
talk is cheap, show others the code and KPI, Keep progress,make a better result.
Survive during the day and develop at night。
目录
概 述
HSSFSheet.removeRow( int rowNum )方法。
/**
- 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);
}
}
}
小结
参考
资料和推荐阅读
1.链接: 参考资料.
本文介绍了如何使用Apache POI的HSSFSheet类的removeRow方法来删除Excel工作表中的行。通过指定行索引,可以有效地移除指定行,并通过shiftRows方法调整后续行的位置。此外,还提供了代码示例展示删除最后一行的特殊情况。Apache POI是一个流行的Java库,用于处理Microsoft Office格式的文件。
2256

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



