跳到主要内容

AddElement

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

语法

expression.AddElement(nPos, oElement);

expression - 表示 ApiTableCell 类的变量。

参数

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

返回值

boolean

示例

在文档中表格单元格内的特定位置放置新段落。

// How do I insert a paragraph at a chosen spot within a table cell in a document?

// Populate a cell with a paragraph of text by targeting its exact index 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);
cell.AddElement(0, paragraph);