Skip to main content

MergeCells

Merges an array of cells.

If the merge is done successfully, it will return the resulting merged cell, otherwise the result will be "null".

warning

The number of cells in any row and the number of rows in the current table may be changed.

Syntax​

expression.MergeCells(aCells);

expression - A variable that represents an ApiTable class.

Parameters​

NameRequired/OptionalData typeDefaultDescription
aCellsRequiredApiTableCell[]The array of cells to be merged.

Returns​

ApiTableCell

Example​

Combine multiple table cells into a single cell in a document.

// How do I merge several cells together into one in a document?

// Reduce cell count by joining adjacent cells into a unified area in a document.

let doc = Api.GetDocument();
let tableStyle = doc.CreateStyle("CustomTableStyle", "table");
tableStyle.SetBasedOn(doc.GetStyle("Bordered"));
let table = Api.CreateTable(5, 5);
table.SetWidth("percent", 100);
table.SetStyle(tableStyle);
let cell = table.MergeCells([table.GetRow(1).GetCell(1), table.GetRow(1).GetCell(2), table.GetRow(2).GetCell(1), table.GetRow(2).GetCell(2)]);
cell.GetContent().GetElement(0).AddText("Merged cell");
doc.Push(table);