Skip to main content

Paragraphs

Paragraphs

JSSDK: 1.2.2、zOffice2022.3 FP2 支持

文档中所有段落对象集合。

属性

count

段落的数量

语法

Application.ActiveDocument.Paragraphs.count

Application: 文档类型应用对象

返回值

count: Promise<number>

示例

async function example() {
const count = await Application.ActiveDocument.Paragraphs.count;
}

方法

item

根据段落序号或段落id获取单个段落

语法

Application.ActiveDocument.Paragraphs.item(key)

Application: 文档类型应用对象

参数

属性数据类型必填说明
keynumber | string段落序号(序号从1开始) | 段落Id

返回值

Promise<Word.Paragraph>

示例

async function example() {
// 通过index获取段落
const paragraphByIndex = await Application.ActiveDocument.Paragraphs.item(1);
// 通过id获取段落
const paragraph = await Application.ActiveDocument.Paragraphs.item(paragraphByIndex.id);
}

add

在当前文档的指定顺序位置插入一个新的包含指定文本的段落

语法

Application.ActiveDocument.Paragraphs.add(text, index)

Application:文档类型应用对象

参数

属性数据类型必填说明
textstring插入段落的纯文本文字内容
indexnumber段落序号(从1开始,默认插入到文档末尾)

返回值

Promise<Word.Paragraph>

示例

async function example(text, index) {
let paragraph = await Application.ActiveDocument.Paragraphs.add(text, index);
}