1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| 1 先用shiftRows方法将行向下移动,
void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight);
2 当移动行后,在Sheet对象中row会空出来几个比如从1~3 8~15.这时3~8是没有row对象的。 需要我们来自己创建row对象,并依据上面的样式补充单元格。 Row rowSource = sheet.getRow(n); for (int i = startRow; i < startRow+count; i++) { Row rowInsert = sheet.createRow(i); rowInsert.setRowStyle(rowSource.getRowStyle()); rowInsert.setHeight(rowSource.getHeight()); for (int col = 0; col < rowSource.getLastCellNum(); col++) { Cell cellsource = rowSource.getCell(col); Cell cellInsert = rowInsert.createCell(col); cellInsert.setCellStyle(cellsource.getCellStyle()); CellRangeAddress region = new CellRangeAddress(i, i, 3, 4); CellRangeAddress region2 = new CellRangeAddress(i, i, 6, 8); sheet.addMergedRegion(region); sheet.addMergedRegion(region2); }
}
|