合并单元格
Contents
[
Hide
]
Aspose.Cells - 合并单元格
Cells 类具有一些有用的方法。例如,合并方法将单元格合并为指定单元格范围内的单个单元格。
Java
//Create a Workbook.
Workbook wbk = new Workbook();
//Create a Worksheet and get the first sheet.
Worksheet worksheet = wbk.getWorksheets().get(0);
//Create a Cells object to fetch all the cells.
Cells cells = worksheet.getCells();
//Merge some Cells (C6:E7) into a single C6 Cell.
cells.merge(5,2,2,3);
//Input data into C6 Cell.
worksheet.getCells().get(5,2).setValue("This is a test of merging");
//Save the Workbook.
wbk.save(dataDir + "merge_Aspose.xls");
Apache POI SS - HSSF XSSF - 合并单元格
可以使用 Sheet.addMergedRegion 合并单元格。
Java
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)
));
下载运行代码
下载示例代码
获取更多详细信息,请访问 合并和取消合并单元格。