跳到主要内容

GetParentTable

返回包含当前段落的表格。

语法

expression.GetParentTable();

expression - 表示 ApiParagraph 类的变量。

参数

此方法没有任何参数。

返回值

ApiTable | null

示例

此示例展示如何获取包含段落的表格。

// How to get the parent table of the paragraph.

// Remove the cell from the parent element.

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.");
let cell = table.GetCell(0, 0);
table.AddElement(cell, 0, paragraph);
let parentTable = paragraph.GetParentTable();
cell = parentTable.GetRow(2).GetCell(0);
parentTable.RemoveRow(cell);