跳到主要内容

Cell

Cell

JSSDK: 1.2.0、zOffice2022.3 支持

表格单元格

属性

range

JSSDK: 1.7.1、zOffice V7.2 FP1 支持

获取单元格范围

语法

Cell.range

Cell: 单元格对象

返回值

Promise<Word.Range>

示例

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const range = await cell.range;
}

方法

getRowSpan

获取单元格的行跨度。

语法

cell.getRowSpan()

cell: 单元格对象

返回值

Promise<number>

示例

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const cellRowSpan = await cell.getRowSpan();
}

getColSpan

获取单元格的列跨度。

语法

cell.getColSpan()

cell: 单元格对象

返回值

Promise<number>

返回值

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const cellColSpan = await cell.getColSpan();
}

getIndex

获取单元格所在行列位置。

语法

cell.getIndex()

cell: 单元格对象

返回值

Promise<[rowIndex, columnIndex]>

示例

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const cellIndex = await cell.getIndex();
}

getHtml

获取单元格的html结构。

语法

cell.getHtml()

cell: 单元格对象

返回值

Promise<string>

示例

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const getHtml = await cell.getHtml();
}

setHtml

设置单元格的html结构。

语法

cell.setHtml(htmlString)

cell: 单元格对象

参数

属性数据类型必填说明
htmlStringstring单元格的Html结构

返回值

Promise<boolean>

示例

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const success = await cell.setHtml("<table><tbody><colgroup><col style='width:137.25pt'/></colgroup><tr><td><p>新的内容</p></td></tr></tbody></table>");
}

getText

获取单元格的文本内容。

语法

cell.getText()

cell: 单元格对象

返回值

Promise<string>

示例

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const getText = await cell.getText();
}

setText

设置单元格的文本内容。

语法

cell.setText(content)

cell: 单元格对象

参数

属性数据类型必填说明
contentstring文本内容

返回值

Promise<boolean>

示例

async function example() {
const table = await Application.ActiveDocument.Tables.item(1);
const row = await table.Rows.item(1);
const cell = await row.Cells.item(1);
const success = await cell.setText('新的内容');
}