GridDesktop中合并和取消合并单元格
Contents
[
Hide
]
在本主题中,我们将讨论工作表的合并和取消合并单元格的实用功能。在需要跨越一些行或列以提高数据可读性的情况下,此功能非常有用。
合并单元格
要将单元格合并为一个大单元格,请按照以下步骤操作:
- 访问任何所需的工作表
- 创建要合并的单元范围
- 将单元范围合并成大单元格
您可以使用工作表的合并方法来合并单元格。然而,可以使用CellRange对象来定义单元范围。
This file contains hidden or 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 worksheet of the Grid that is currently active | |
Worksheet sheet = gridDesktop1.GetActiveWorksheet(); | |
// Creating a CellRange object starting from "B4" to "C6" | |
CellRange range = new CellRange("B4", "C6"); | |
// Merging a range of cells | |
sheet.Merge(range); |
取消合并单元格
要将大单元格取消合并为多个单元格,请按照以下步骤操作:
- 访问任何所需的工作表
- 访问需要取消合并的合并单元格
- 使用合并单元格的位置取消合并大单元格为多个单元格
您可以使用工作表的取消合并方法来使用其位置取消合并单元格。
This file contains hidden or 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 worksheet of the Grid that is currently active | |
Worksheet sheet = gridDesktop1.GetActiveWorksheet(); | |
// Accessing the merged cell that is currently in focus | |
GridCell cell = sheet.GetFocusedCell(); | |
// Unmerging a cell using its location | |
sheet.Unmerge(cell.Location); |
当您将单元格合并为一个单元格时,合并单元格的左上角单元格(在单元范围内)的格式设置将应用于合并单元格,但当取消合并单元格时,所有取消合并的单元格将保留其格式设置。