合并和取消合并单元格
Contents
[
Hide
]
Aspose.Cells.GridWeb提供了一个方便的实用功能,可以将单元格合并成一个大单元格。本主题描述了如何以编程方式合并单元格。
合并单元格
通过调用Cells集合的Merge方法,将工作表中的多个单元格合并成一个单元格。在调用Merge方法时,指定要合并的单元格范围。
如果合并多个单元格,且每个单元格都包含数据,则在合并后仅保留范围中左上角单元格的内容。其他单元格中的数据不会丢失。如果取消合并单元格,则每个单元格都会恢复其数据。
四个单元格合并为一个
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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方法相同,并执行取消合并单元格的操作。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |