跳到主要内容

AddElement

使用在单元格中的位置添加段落、表格或块级内容控件。

语法

expression.AddElement(oCell, nPos, oElement);

expression - 表示 ApiTable 类的变量。

参数

名称必需/可选数据类型默认值描述
oCell必需ApiTableCell将添加指定元素的单元格。
nPos必需number将添加指定元素的单元格中的位置。
oElement必需DocumentElement将在当前位置添加的文档元素。

返回值

boolean

示例

将段落放入文档中表格的特定单元格。

// How do I insert content into a particular cell of a table in a document?

// Populate a table cell with a text block at a given position in a document.

let doc = Api.GetDocument();
let tableStyle = doc.CreateStyle("CustomTableStyle", "table");
tableStyle.SetBasedOn(doc.GetStyle("Bordered"));
let table = Api.CreateTable(3, 3);
table.SetWidth("percent", 100);
table.SetStyle(tableStyle);
doc.Push(table);
let paragraph = Api.CreateParagraph();
paragraph.AddText("This is just a sample text in the first cell.");
let cell = table.GetCell(0, 0);
table.AddElement(cell, 0, paragraph);