java POI 实现Excel合并单元格

来源:互联网 发布:推广软件大全 编辑:程序博客网 时间:2024/04/29 07:38
Workbook wb = new HSSFWorkbook();    Sheet sheet = wb.createSheet("new sheet");    Row row = sheet.createRow((short) 1);    Cell cell = row.createCell((short) 1);    cell.setCellValue("This is a test of merging");    sheet.addMergedRegion(new CellRangeAddress(            1, //first row (0-based)            1, //last row  (0-based)            1, //first column (0-based)            2  //last column  (0-based)    ));    // Write the output to a file    FileOutputStream fileOut = new FileOutputStream("E:\\standarcode\\workbook.xls");    wb.write(fileOut);    fileOut.close();

效果:


0 0