Объединение и разделение Cells
Contents
[
Hide
]
Aspose.Cells.GridWeb имеет удобную служебную функцию, позволяющую объединять ячейки в одну большую ячейку. В этом разделе описывается, как программно объединять ячейки.
Объединение Cells
Объедините несколько ячеек листа в одну, вызвав метод Merge коллекции Cells. Укажите диапазон ячеек, которые необходимо объединить при вызове метода 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 коллекции Cells, который принимает те же параметры, что и метод 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); |