Merging Multiple Cells in the Spreadsheet
Environment
| Product | Progress® Kendo UI® Spreadsheet for Angular |
Description
I want to merge cells in the Kendo UI for Angular Spreadsheet. I need to merge specific cells programmatically. I also want to know if I can implement dynamic cell merging based on user selection.
This knowledge base article also answers the following questions:
- How do I merge selected cells dynamically in Kendo UI for Angular Spreadsheet?
- Can I merge cells programmatically in Kendo UI for Angular Spreadsheet?
- What is the method to merge cells using
SpreadsheetWidgetin Angular?
Solution
To merge cells in the Kendo UI for Angular Spreadsheet dynamically, use the SpreadsheetWidget API. The activeSheet() method gives you access to the current sheet. The range() combined with merge() lets you merge the selected cells.
Some of the underlying
SpreadsheetWidgetAPI methods (such asselection()andmerge()) are not currently documented in the public API documentation. These methods are part of the internal widget API and may require type assertions (as any) when you use them in TypeScript.
Here is how you can implement dynamic cell merging in your Angular component:
- Set up a ViewChild reference to access the
SpreadsheetComponent:
<kendo-spreadsheet #spreadsheet></kendo-spreadsheet>
@ViewChild('spreadsheet', { static: false })
public spreadsheet!: SpreadsheetComponent;
-
Get the
SpreadsheetWidgetreference from theSpreadsheetComponent:typescriptconst spreadsheetWidget = this.spreadsheet.spreadsheetWidget; if (!spreadsheetWidget) { return; } -
Access the active sheet using the
activeSheet()method:typescriptconst activeSheet = spreadsheetWidget.activeSheet() as any; if (!activeSheet) { return; } -
Get the current selection with
selection():typescriptconst selection = activeSheet.selection(); -
Merge the selected range using the
range(selection).merge()method:typescriptactiveSheet.range(selection).merge();
The following example shows how to merge selected cells or specific ranges programmatically in the Kendo UI for Angular Spreadsheet. You can select multiple cells using left mouse click and Shift key, then click the Merge Cells button to merge them.