Get Started
Usage API
More information

MergeCells

MergeCells(aCells) → { ApiTableCell }

Merge an array of cells. If the merge is done successfully, it will return the resulting merged cell, otherwise the result will be "null". The number of cells in any row and the number of rows in the current table may be changed.

Parameters:

Name Type Description
aCells Array.<ApiTableCell>

The array of cells to be merged.

Returns:

Type
ApiTableCell

Example

Copy code
builder.CreateFile("docx");
oDocument = Api.GetDocument();
oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");
oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered - Accent 5"));
oTable = Api.CreateTable(5, 5);
oTable.SetWidth("percent", 100);
oTable.SetStyle(oTableStyle);
oCell = oTable.MergeCells([oTable.GetRow(1).GetCell(1), oTable.GetRow(1).GetCell(2), oTable.GetRow(2).GetCell(1), oTable.GetRow(2).GetCell(2)]);
oCell.GetContent().GetElement(0).AddText("Merged cell");
oDocument.Push(oTable);
builder.SaveFile("docx", "MergeCells.docx");
builder.CloseFile();

Resulting document