跳到主要内容

MergeCells

合并单元格数组。如果合并成功,将返回合并后的单元格,否则返回 “null”。

  • 警告:任何行中的单元格数量和当前表格中的行数可能会更改。

语法

expression.MergeCells(cells);

expression - 表示 ApiTable 类的变量。

参数

名称必需/可选数据类型默认值描述
cells必需ApiTableCell[]要合并的单元格。

返回值

ApiTableCell

示例

在 PDF 中将多个单元格合并为一个统一的单元格。

// How can I join cells together within a table in a PDF?

// Join adjacent cells to form a single larger cell in a PDF.

const doc = Api.GetDocument();
const page = doc.GetPage(0);

const table = Api.CreateTable(2, 4);
const row = table.GetRow(0);
const cell1 = row.GetCell(0);
const cell2 = row.GetCell(1);
table.MergeCells([cell1, cell2]);

const cell = row.GetCell(0);
const content = cell.GetContent();
const paragraph = Api.CreateParagraph();
paragraph.AddText("This cell was formed by merging two cells.");
content.Push(paragraph);

page.AddObject(table);