/**
* 新增一行数据并拷贝上一行的样式
*
* @param sheet
* @param startRow 开始新增行数
* @param cellNum 增加的列数
* @return
*/
private void insertRow(HSSFSheet sheet, int startRow, int cellNum) {
sheet.shiftRows(startRow, sheet.getLastRowNum(), 1, true, false);
//获取当前行
HSSFRow rowSource = sheet.getRow(startRow - 1);
//获取当前行样式
HSSFCellStyle rowStyle = rowSource.getRowStyle();
//新增行
HSSFRow rowInsert = sheet.createRow(startRow);
if (rowStyle != null) {
rowInsert.setRowStyle(rowStyle);
rowInsert.setHeight(rowSource.getHeight());
}
for (int col = 0; col < cellNum; col++) {
HSSFCell cellSource = rowSource.getCell(col);
HSSFCell cellInsert = rowInsert.createCell(col);
HSSFCellStyle cellStyle = cellSource.getCellStyle();
//设置单元格样式
if (cellStyle != null) {
cellInsert.setCellStyle(cellStyle);
}
}
}