跳到主要内容

SelectRange

选择当前表格中的单元格范围。

语法​

expression.SelectRange(startRowIndex, startCellIndex, endRowIndex, endCellIndex);

expression - 表示 ApiTable 类的变量。

参数​

名称必需/可选数据类型默认值描述
startRowIndex必需number起始行索引。
startCellIndex必需number起始行中的起始单元格索引。
endRowIndex必需number结束行索引。
endCellIndex必需number结束行中的结束单元格索引。

返回值​

boolean

示例​

在 PDF 中选择表格中的单元格范围。

// Select several adjacent cells in a table at once in a PDF.

// Create a table and select a 2x2 block of cells starting from the top-left corner.

const doc = Api.GetDocument();
const page = doc.GetPage(0);

const table = Api.CreateTable(3, 3);
page.AddObject(table);

table.SelectRange(0, 0, 1, 1);
const paragraph = Api.CreateParagraph();
paragraph.AddText('Selected cells: ' + table.GetSelectedCells().length);
table.GetCell(0, 0).GetContent().Push(paragraph);