Skip to main content

Comments

Comments

JSSDK: 1.7.1、zOffice v7.2 FP1 支持

一个 Comment 对象的集合,这些对象代表所选内容、区域或文档中的批注。

属性

count

批注的数量

语法

Comments.count

返回值

Promise<number>

示例

// 获取全文批注数量
async function example() {
const count = await Application.ActiveDocument.Comments.count;
}

方法

add

添加批注

语法

Comments.add(text, range)

参数

属性数据类型必填说明
textstring批注内容
rangeWord.Range指定添加批注的区域,默认在当前选区添加

返回值

Promise<Word.Comment>

示例

// 在当前选区添加批注
async function example() {
const comments = Application.ActiveDocument.Comments;
const comment = await comments.add('我的批注');
}

// 在书签区域添加批注
async function example() {
const comments = Application.ActiveDocument.Comments;
const bm = await Application.ActiveDocument.Bookmarks.item('bm');
const range = await bm.range;
const comment = await comments.add('我的批注', range);
}

// 给指定批注添加回复
async function example() {
const comments = Application.ActiveDocument.Comments;
const comment = await comments.item(1);
const replies = await comment.Replies;
const comment = await replies.add('添加批注');
}

item

返回集合中的单个 批注 对象。

语法

Comments.item(index)

参数

属性数据类型必填说明
indexnumber批注在集合中的序号

返回值

Promise<Word.Comment>

示例

// 获取全文中第一个批注
async function example() {
const comments = Application.ActiveDocument.Comments;
const comment = await comments.item(1);
}

toJson

返回集合中的单个 批注 对象的结构化数据。

语法

Columns.toJson()

返回值

Promise<any[]>

{
content: string, // 批注内容
creator: {
uid: string, // 批注创建者 ID
name: string // 批注创建者名字
},
id: string, // 批注ID
pid: string, // 父批注ID(如果是回复,会返回该字段)
time: number, // 批注创建时间戳
done: boolean // 批注是否已解决
}

示例

// 获取全文中所有批注的结构化数据
async function example() {
const comments = Application.ActiveDocument.Comments;
const data = await comments.toJson();
}