POI 合并单元格

private void mergedCell(Sheet sheet, int firstRow, int lastRow, int firstCol, int lastCol, Object value) {
CellRangeAddress region = new CellRangeAddress(firstRow, lastRow, firstCol, lastCol);
sheet.addMergedRegion(region);
Row row = sheet.createRow(firstRow);
Cell cell = row.createCell(firstCol);
if (value instanceof Integer) {
cell.setCellValue((Integer) value);
} else if (value instanceof String) {
cell.setCellValue((String) value);
} else if (value instanceof Double) {
cell.setCellValue((Double) value);
} else if (value instanceof Boolean) {
cell.setCellValue((Boolean) value);
} else if (value instanceof LocalDate) {
cell.setCellValue((LocalDate) value);
} else if (value instanceof LocalDateTime) {
cell.setCellValue((LocalDateTime) value);
} else if (value instanceof RichTextString) {
cell.setCellValue((RichTextString) value);
} else if (value instanceof Calendar) {
cell.setCellValue((Calendar) value);
} else {
cell.setCellValue((String) value);
}

}
posted @ 2022-04-24 13:09  gzhq  阅读(411)  评论(0编辑  收藏  举报