←Select platform

MergedRegions Property

Summary

Provides access to the MergedCellRegions collection associated with the sheet. This property enables the management of merged cell regions within the sheet, offering functionalities to add, remove, or access merged regions.

Syntax

C#
C++/CLI
Python
public MergedCellRegions MergedRegions { get; } 
public:  
   property MergedCellRegions^ MergedRegions 
   { 
      MergedCellRegions^ get() 
   } 
MergedRegions # get  (Sheet) 

Property Value

An instance of the MergedCellRegions class representing the collection of all merged cell regions within the sheet.

Remarks

This property is essential for comprehensive sheet formatting, allowing control and modification of merged cell regions. Through this property, merged regions can be dynamically managed, facilitating the creation of structures.

Example

C#
using Leadtools; 
using Leadtools.Document.LEADOffice.Sheet; 
 
 
public void MergeCellsAndSaveExample() 
{ 
   // Load an Excel workbook from a file 
   var workbook = LEADWorkbookFactory.Create(); 
 
   // Add a new sheet named "MergeExample" or access an existing sheet 
   var sheet = workbook.CreateSheet("MergeExample"); 
 
   // Define the cell range to merge (e.g., A1:B1) 
   var mergeRange = new CellRange(0, 0, 0, 1); // This assumes 0-based indexing for rows and columns 
 
   // Perform the merge operation on the specified cell range 
   sheet.MergedRegions.AddRegion(mergeRange); 
 
   // Optionally, set a value for the merged cells 
   var cell = sheet.CreateRow(0).CreateCell(0); // Access the first cell in the merge range 
   cell.SetCellValue("Merged Cell"); 
 
   // Save the workbook to disk 
   var filePath = Path.Combine(LEAD_VARS.ImagesDir, @"MergedCells.xlsx"); 
   workbook.Save(filePath); 
 
   Console.WriteLine($"Workbook saved with merged cells to {filePath}"); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 

Requirements

Target Platforms

See Also

Sheet Class

Sheet Members

Leadtools.Document.LEADOffice.Sheet Namespace

Help Version 23.0.2024.5.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document.LEADOffice Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.