HSSFRow row9 = sheetAt.getRow(9); 我想在row9的下方插入3行一样的,代码怎么写
时间: 2024-03-02 18:49:53 浏览: 68
可以按照以下方式在`row9`的下方插入3行:
```java
// 获取row9的下一个位置(即第10行)
int nextRowIndex = row9.getRowNum() + 1;
// 在nextRowIndex位置插入一行数据
HSSFRow newRow = sheetAt.createRow(nextRowIndex);
// 将row9中的单元格复制到新行中
for (int i = row9.getFirstCellNum(); i < row9.getLastCellNum(); i++) {
HSSFCell cell = row9.getCell(i);
if (cell != null) {
HSSFCell newCell = newRow.createCell(i, cell.getCellType());
newCell.setCellStyle(cell.getCellStyle());
newCell.setCellValue(cell.getStringCellValue());
}
}
// 再次复制row9的单元格到新行中,插入第2行数据
newRow = sheetAt.createRow(nextRowIndex + 1);
for (int i = row9.getFirstCellNum(); i < row9.getLastCellNum(); i++) {
HSSFCell cell = row9.getCell(i);
if (cell != null) {
HSSFCell newCell = newRow.createCell(i, cell.getCellType());
newCell.setCellStyle(cell.getCellStyle());
newCell.setCellValue(cell.getStringCellValue());
}
}
// 再次复制row9的单元格到新行中,插入第3行数据
newRow = sheetAt.createRow(nextRowIndex + 2);
for (int i = row9.getFirstCellNum(); i < row9.getLastCellNum(); i++) {
HSSFCell cell = row9.getCell(i);
if (cell != null) {
HSSFCell newCell = newRow.createCell(i, cell.getCellType());
newCell.setCellStyle(cell.getCellStyle());
newCell.setCellValue(cell.getStringCellValue());
}
}
```
请注意,这里假设您正在使用的是HSSF API来操作Excel文件。如果您正在使用XSSF API,代码会略有不同,但大致的思路应该是相同的。
阅读全文
相关推荐

















