1、使用poi合并单元格
public static void main(String[] args) throws Exception {
// 定义一个工作簿
Workbook workbook = new XSSFWorkbook();
// 创建一个sheet页
Sheet sheet = workbook.createSheet("第一个sheet页");
// 创建一个行
Row row = sheet.createRow(0);
// 创建单元格
row.createCell(0).setCellValue("测试内容");
row.createCell(1).setCellValue("测试内容2");
// 合并单元格,合并后的内容取决于合并区域的左上角单元格的值
CellRangeAddress region = new CellRangeAddress(0,3,0,3);
sheet.addMergedRegion(region);
FileOutputStream fileOutputStream = new FileOutputStream("D:\\用poi测试合并单元格.xlsx");
workbook.write(fileOutputStream);
fileOutputStream.close();
}
来源:https://www.cnblogs.com/lkc9/p/12256273.html