合并或取消合并单元格范围
Contents
[
Hide
]
您可以使用 Aspose.Cells 来合并或拆分一系列单元格。Aspose.Cells 为此提供了 Range.Merge() 和 Range.UnMerge() 方法。本文解释了如何将一系列单元格合并为单个单元格。
示例
以下示例代码首先创建范围 - A1:D4 - 然后使用 Range.Merge() 方法将范围中的单元格合并为单个单元格。类似地,您可以通过创建范围并调用 Range.UnMerge() 方法来拆分单元格。
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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create a workbook | |
Workbook workbook = new Workbook(); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Create a range | |
Range range = worksheet.Cells.CreateRange("A1:D4"); | |
// Merge range into a single cell | |
range.Merge(); | |
// Save the workbook | |
workbook.Save(dataDir+ "output.out.xlsx"); |