跳到主要内容

GetParentTable

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

语法

expression.GetParentTable();

expression - 表示 ApiParagraph 类的变量。

参数

此方法没有任何参数。

返回值

ApiTable | null

示例

检索文档中包含给定段落的表格。

// How do I get the table that a paragraph belongs to in a document?

// Remove a row from the parent table by navigating up from a paragraph inside one of its cells 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.");
let cell = table.GetCell(0, 0);
table.AddElement(cell, 0, paragraph);
let parentTable = paragraph.GetParentTable();
cell = parentTable.GetRow(2).GetCell(0);
parentTable.RemoveRow(cell);