跳到主要内容

AddElement

Adds a paragraph or a table or a blockLvl content control using its position in the cell.

Syntax

expression.AddElement(oCell, nPos, oElement);

expression - A variable that represents a ApiTable class.

Parameters

NameRequired/OptionalData typeDefaultDescription
oCellRequiredApiTableCellThe cell where the specified element will be added.
nPosRequirednumberThe position in the cell where the specified element will be added.
oElementRequiredDocumentElementThe document element which will be added at the current position.

Returns

This method doesn't return any data.

Example

This example adds a paragraph using its position in the cell.

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);