- Document Solutions for Excel, .NET Edition Overview
- Key Features
- Getting Started
-
Features
-
Worksheet
- Work with Worksheets
-
Range Operations
- Access a Range
- Get Intersection, Union and Offset Range
- Access Areas in a Range
- Get Range and Range Area
- Get Special Cell Ranges
- Access Cells, Rows and Columns in a Range
- Get Address of Cell Range
- Cut or Copy Cell Ranges
- Cut or Copy Shape, Slicer, Chart and Picture
- Paste or Ignore Data in Hidden Range
- Find and Replace Data
- Get Row and Column Count
- Hide Rows and Columns
- Insert And Delete Cell Ranges
- Insert and Delete Rows and Columns
- Merge Cells
- Auto Merge Cells
- Protect Cell Range
- Set Values to a Range
- Set Custom Objects to a Range
- Set Row Height and Column Width
- Auto Fit Row Height and Column Width
- Work with Used Range
- Measure Digital Width
- Set Default Values for Cell Range
- Set Cell Background Image for Cell Range
- Ignore Errors in Cell Range
- Customize Worksheets
- Worksheet Views
- Cell Types
- Quote Prefix
- Tags
- Rich Text
- Background Image
- Workbook
- Comments
- Hyperlinks
- Sort
- Filter
- Group
- Conditional Formatting
- Data Validations
- Data Binding
- Import Data
- Digital Signatures
- Formulas
- Custom Functions
- Shapes
- Document Properties
- Styles
- Form Controls
- Barcodes
- Themes and Colors
- Chart
- Table
- Pivot Table
- Pivot Chart
- Sparkline
- Slicer
- Logging
- Defined Names
-
Worksheet
- Templates
- File Operations
- Document Solutions Data Viewer
- API Reference
- Release Notes
Auto Merge Cells
DsExcel allows you to add auto-merge information for a range that needs the merging of neighboring cells containing identical text using AutoMerge method of IWorksheet interface. AutoMerge method initiates an automatic merging operation that only takes effect at the moment of exporting the workbook to PDF, HTML, Image, .xlsx, .sjs, or Json with IncludeAutoMergedCells property of XlsxSaveOptions, SjsSaveOptions, SerializationOptions, PdfSaveOptions, ImageSaveOptions, and HtmlSaveOptions classes set to true.
AutoMerge method has the following parameters that help in adding and customizing the auto-merge operation:
Parameter Name | Description |
|---|---|
range | The range for the auto-merge. |
direction | The direction for the auto-merge. The default value is Column. AutoMergeDirection provides the following auto-merge directions:
|
mode | The mode for the auto-merge. The default value is Free. AutoMergeMode provides the following auto-merge modes:
|
selectionMode | The selection mode for the auto-merge. The default value is Source. AutoMergeSelectionMode provides the following auto-merge selection modes:
Note: selectionMode parameter is only applicable to SpreadJS. |
Refer to the following example code to add auto-merge information for a range and export the workbook as .xlsx, .sjs, .pdf, and .png files:
// Create a new workbook.
var workbook = new Workbook();
// Open existing workbook.
workbook.Open("Regional_Product_List.xlsx");
// Get active worksheet.
var worksheet = workbook.ActiveSheet;
// Add auto-merge range with restricted mode and merged selection mode.
worksheet.AutoMerge(worksheet.UsedRange, AutoMergeDirection.Column, AutoMergeMode.Restricted, AutoMergeSelectionMode.Merged);
// Set IncludeAutoMergedCells to true to include the automatically merged cells.
// Set XlsxSaveOptions to export workbook as XLSX file.
XlsxSaveOptions xlsxOptions = new XlsxSaveOptions
{
IncludeAutoMergedCells = true
};
// Set SjsSaveOptions to export workbook as .sjs file.
SjsSaveOptions sjsOptions = new SjsSaveOptions
{
IncludeAutoMergedCells = true
};
// Set PdfSaveOptions to export workbook as PDF file.
PdfSaveOptions pdfOptions = new PdfSaveOptions
{
IncludeAutoMergedCells = true
};
// Set ImageSaveOptions to export workbook as PNG file.
ImageSaveOptions pngOptions = new ImageSaveOptions
{
IncludeAutoMergedCells = true
};
// Save workbook as XLSX file.
workbook.Save("AutoMerge.xlsx", xlsxOptions);
// Save workbook as .sjs file.
workbook.Save("AutoMerge.sjs", sjsOptions);
// Save workbook as PDF file.
workbook.Save("AutoMerge.pdf", pdfOptions);
// Save workbook as PNG file.
worksheet.ToImage("AutoMerge.png", pngOptions);Without AutoMerge | With AutoMerge |
|---|---|
!type=note
Note:
The auto-merge operation will throw an exception if the ranges intersect with each other. For example, "A1:C3, B2:D4".
The auto-merge operation will throw an exception if the range intersects an existing auto-merge range.
The auto-merge information is added for each area if the range has multiple areas. For example, "A1:B2, D3:E4."
Inserting or deleting rows or columns will affect the auto-merge range. Any other API operations will not affect the auto-merge range.
The auto-merge operation will not change the workbook, so MergeCells and MergeArea properties of IRange interface cannot obtain the results of the auto-merge operation.
The auto-merged cells will be stored as normal span ranges in .xlsx, .sjs, and .json files if IncludeAutoMergedCells is true.