我可以使用POI创建以下excel:
从图像中可以清楚地看出,每个表都有两个值即 . Val One和Val Two .
但是,我希望将表名称两个单元格合并到第一列中的一个单元格中,如下所示:
如何在POI中实现这一目标?
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("workbook.xls"); wb.write(fileOut); fileOut.close();
1 回答