Comment
Comment
JSSDK: 1.7.1、zOffice v7.2 FP1 支持
批注
属性
range
批注所在正文区域
语法
Comment.range
返回值
Promise< Word.Range>
示例
// 获取正文中第一个批注的区域
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const range = await comment.range;
}
creator
批注创建者
语法
Comment.creator
返回值
Promise<{name:string, uid:string}>
示例
// 获取正文中第一个批注的创建者
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const creator = await comment.creator;
}
content
批注内容
语法
Comment.content
返回值
Promise< string>
示例
// 获取正文中第一个批注的内容
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const content = await comment.content;
}
time
批注创建/修改时间
语法
Comment.time
返回值
Promise< number>
示例
// 获取正文中第一个批注的创建/修改时间
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const time = await comment.time;
}
done
批注解决状态,读/写
语法
Comment.done
返回值
Promise< boolean>
示例
// 解决正文中第一个批注
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
comment.done = true;
}
// 重开正文中第一个批注
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
comment.done = false;
}
// 获取正文中第一个批注的状态
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const isDone = await comment.done;
}
parent
返回回复的父批注
语法
Comment.parent
返回值
Promise< Word.Comment>
示例
// 获取回复的父批注
async function example() {
const comment = await Application.ActiveDocument.Comments.item(3);
const parent = await comment.parent;
if (parent) {
const content = await parent.content;
}
}
Replies
返回一个 Comment 集合,这些注释对象是指定批注的子级。 此为只读属性。
语法
Comment.Replies
返回值
Promise<Word.Comments>
示例
// 获取正文中第一个批注的回复数目
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const replies = await comment.Replies;
const count = await replies.count;
}
方法
delete
删除批注。
语法
comment.delete()
返回值
Promise<boolean> 是否删除成功
示例
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const success = await comment.delete();
}
toJson
返回批注结构化数据
语法
comment.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 comment = await Application.ActiveDocument.Comments.item(1);
const data = await comment.toJson();
}
focus
定位批注
语法
comment.focus()
返回值
无
示例
// 定位文档中第一个批注
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
await comment.focus();
}
setHidden
设置批注框隐藏
语法
comment.setHidden(hide)
参数
| 属性 | 数据类型 | 必填 | 说明 |
|---|---|---|---|
| hide | boolean | 是 | 是否隐藏 |
返回值
无
示例
// 隐藏文档中第一个批注
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
await comment.setHidden(true);
}
// 取消隐藏文档中第一个批注
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
await comment.setHidden(false);
}
// 隐藏文档中第一个批注的第1条回复
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
const replies = await comment.Replies;
const reply = await replies.item(1);
await reply.setHidden(true);
}
setHighlightColor
设置批注标记颜色
语法
comment.setHighlightColor(color)
参数
| 属性 | 数据类型 | 必填 | 说明 |
|---|---|---|---|
| color | string | 是 | 十六进制颜色码 |
返回值
无
示例
// 设置文档中第一个批注的批注标记颜色为红色
async function example() {
const comment = await Application.ActiveDocument.Comments.item(1);
await comment.setHighlightColor('#ff0000');
}