Appearance
批注(Comments)
Comment 对象的集合,这些对象代表指定选定内容、范围或文档中的批注
属性列表
属性 | 说明 |
---|---|
Count | 获取批注个数 |
方法列表
方法 | 返回类型 | 说明 |
---|---|---|
Add() | 无 | 添加批注 |
DeleteComment() | 无 | 删除单个批注 |
DeleteAll() | 无 | 删除所有批注 |
GetComments() | Comment 对象的集合 | 全部书签 |
Item() | Comment | 单个批注对象 |
ModifyComment() | 无 | 修改批注内容 |
ReplyComment() | 无 | 回复批注 |
GoToComment() | 无 | 跳转到批注位置 |
SetSolved() | 无 | 设置批注解决状态 |
Count
获取批注个数
语法
表达式.ActiveDocument.Comments.Count
返回值
返回 Number
代表文档内容控件的数量。
示例
js
async function example() {
await jssdk.ready();
const app = jssdk.Application;
// 添加批注
await app.ActiveDocument.Comments.Add({
text: "WebOffice",
range: {
start: 1,
end: 10,
},
});
// 获取批注数量
const count = await app.ActiveDocument.Comments.Count;
console.log(count);
}
Add()
添加批注
语法
表达式.ActiveDocument.Comments.Add({text, useSelection, range})
参数
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
text | String | 是 | 批注内容。 | |
useSelection | Boolean | 否,与 range 必选其一 | 是否使用当前选区范围 | |
range | Range{} | 否,与 useSelection 必选其一 | 批注的文本起止区域。 | |
range.start | Number | 是 | 区域开始位置 | |
range.end | Number | 是 | 区域结束位置 |
IMPORTANT
无论使用当前选区还是指定 range ,如果范围内没有有效文本,则批注不会添加成功
示例
js
async function example() {
await jssdk.ready();
const app = jssdk.Application;
// 使用指定范围添加批注1
await app.ActiveDocument.Comments.Add({
text: "批注1",
range: {
start: 1,
end: 10,
},
});
// 使用当前选区添加批注2
await app.ActiveDocument.Comments.Add({
text: "批注2",
useSelection: true
});
}
DeleteComment()
删除单条批注
语法
表达式.ActiveDocument.Comments.DeleteComment({commentId})
参数
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
commentId | String | 是 | 批注id |
示例
js
async function example() {
await jssdk.ready();
const app = jssdk.Application;
// 删除批注
await app.ActiveDocument.Comments.DeleteComment({commentId: '123'});
}
DeleteAll()
删除所有批注
语法
表达式.ActiveDocument.Comments.DeleteAll()
示例
js
async function example() {
await jssdk.ready();
const app = jssdk.Application;
// 删除全部批注
await app.ActiveDocument.Comments.DeleteAll();
}
GetComments()
全量批注集合
语法
表达式.ActiveDocument.Comments.GetComments()
返回值
返回 Comment 对象集合,单个批注属性见 Item()
示例
js
async function example() {
await jssdk.ready();
const app = jssdk.Application;
// 添加批注
await app.ActiveDocument.comments.Add({
text: "WebOffice",
range: {
start: 1,
end: 10,
},
});
// 获取全量批注
const comments = await app.ActiveDocument.Comments.GetComments();
console.log(comments);
}
Item()
批注集合的单个批注
语法
表达式.ActiveDocument.Comments.Item(key)
参数
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
key | Number 或 String | 是 | 如果是数字,则为索引值;如果是字符,则为批注id |
返回值
返回 Comment 对象,拥有以下属性和方法
属性列表
属性 | 类型 | 说明 |
---|---|---|
Id | String | 批注id |
UserName | String | 作者名 |
UserId | String | 作者id |
Text | String | 批注内容 |
QuoteText | String | 批注引用的文本 |
Date | Number | 批注添加的时间戳 |
方法列表
方法 | 说明 | 参数 |
---|---|---|
SetSolved(bSolved) | 设置批注的解决状态 | bSolved: Boolean ,必须,默认值无。true 为解决,false 为未解决设置批注的解决状态 |
示例
js
async function example() {
await jssdk.ready();
const app = jssdk.Application;
// 添加批注
await app.ActiveDocument.comments.Add({
text: "WebOffice",
range: {
start: 1,
end: 10,
},
});
// 单个批注对象
const firstComment = await app.ActiveDocument.comments.Item(1);
console.log(await firstComment.Text); // 批注内容
console.log(await firstComment.UserName); // 批注作者
await firstComment.SetSolved(true); // 设置为已解决
}
ModifyComment()
修改单条批注
语法
表达式.ActiveDocument.Comments.ModifyComment({commentId, text})
参数
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
commentId | String | 是 | 批注id | |
text | String | 是 | 批注的新内容 |
示例
js
async function example() {
await jssdk.ready();
const app = jssdk.Application;
// 添加批注
await app.ActiveDocument.comments.Add({
text: "WebOffice",
range: {
start: 1,
end: 10,
},
});
// 单个批注对象
const firstComment = await app.ActiveDocument.comments.Item(1);
// 修改批注
const commentId = firstComment.Id;
await app.ActiveDocument.Comments.ModifyComment({commentId, text: '新的批注内容'});
}
ReplyComment()
回复单条批注
语法
表达式.ActiveDocument.Comments.ReplyComment({commentId, text})
参数
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
commentId | String | 是 | 批注id | |
text | String | 是 | 批注的回复内容 |
示例
js
async function example() {
await jssdk.ready();
const app = jssdk.Application;
// 添加批注
await app.ActiveDocument.comments.Add({
text: "WebOffice",
range: {
start: 1,
end: 10,
},
});
// 单个批注对象
const firstComment = await app.ActiveDocument.comments.Item(1);
// 回复批注
const commentId = firstComment.Id;
await app.ActiveDocument.Comments.ReplyComment({commentId, text: '批注的回复内容'});
}
GoToComment()
跳转到某条批注
语法
表达式.ActiveDocument.Comments.GoToComment({commentId})
参数
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
commentId | String | 是 | 批注id |
示例
js
async function example() {
await jssdk.ready();
const app = jssdk.Application;
// 添加批注
await app.ActiveDocument.comments.Add({
text: "WebOffice",
range: {
start: 1,
end: 10,
},
});
// 单个批注对象
const firstComment = await app.ActiveDocument.comments.Item(1);
// 跳转到批注
const commentId = firstComment.Id;
await app.ActiveDocument.Comments.GoToComment({commentId});
}
SetSolved()
修改某条批注的解决状态
语法
表达式.ActiveDocument.Comments.SetSolved({commentId, bSolved})
参数
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
commentId | String | 是 | 批注id | |
bSolved | Boolean | 是 | 解决状态 |
示例
js
async function example() {
await jssdk.ready();
const app = jssdk.Application;
// 添加批注
await app.ActiveDocument.comments.Add({
text: "WebOffice",
range: {
start: 1,
end: 10,
},
});
// 单个批注对象
const firstComment = await app.ActiveDocument.comments.Item(1);
// 将第一条批注设置为已解决
const commentId = firstComment.Id;
await app.ActiveDocument.Comments.SetSolved({commentId, bSolved: true});
}