合并和取消合并单元格

合并单元格

通过调用Cells集合的Merge方法,将工作表中的多个单元格合并成一个单元格。在调用Merge方法时,指定要合并的单元格范围。

四个单元格合并为一个

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Accessing the reference of the worksheet that is currently active
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];
// Merging cells starting from the cell with 3rd row and 3rd column.
// 2 rows and 2 columns will be merged from the starting cell
sheet.Cells.Merge(2, 2, 2, 2);

取消合并单元格

要取消合并单元格,使用Cells集合的UnMerge方法,其参数与Merge方法相同,并执行取消合并单元格的操作。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Accessing the reference of the worksheet that is currently active
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];
// Unmerging cells starting from the cell with 3rd row and 3rd column.
// 2 rows and 2 columns will be unmerged from the starting cell
sheet.Cells.UnMerge(2, 2, 2, 2);