CommentsAsJson
CommentsAsJson 获取当前Word文档中所有键盘批注内容的JSON对象。通常用来遍历Word文档中的所有键盘批注。
语法:
let commentsJson = pageofficectrl.word.CommentsAsJson;
返回值为json字符串,例如返回值为:[{"id":0,"date":45428.575000,"author":"张三"},{"id":1,"date":45428.540972,"author":"李四"},{"id":2,"date":42273.664583,"author":"王五"},{"id":3,"date":42253.672222,"author":"赵六"}]
示例:
//遍历所有键盘批注
function commentsList() {
let commentsListJson =JSON.parse(pageofficectrl.word.CommentsAsJson)
for (let item of commentsListJson) {
let baseDate = new Date(Date.UTC(1899, 11, 30));
let iDate = new Date(baseDate.getTime() + item.date* 24 * 60 * 60 * 1000 - 8 * 60 * 60 * 1000);
const pad = (num) => (num < 10 ? '0' + num : num);
let itemDate = iDate.getFullYear()+'-'+pad(iDate.getMonth() + 1)+'-'+pad(iDate.getDate())+' '+pad(iDate.getHours())+':'+pad(iDate.getMinutes());
alert( item.id + ":" +itemDate+"[" +item.author+"]:"+ pageofficectrl.word.GetTextFromComment(parseInt(item.id)) );
}
}