-1

我正在使用office js。我的加载项在与 mac system office 和 office 365 一起正常工作的单元格中插入了一条评论,但我无法在 windows system office 中插入评论。Office 2016 的版本。我做错了什么?请指导我谢谢。

这是我的代码片段

await Excel.run(async (ctx) => {    let wb = ctx.workbook;
       await ctx.sync().then(async () => {
               try {
                   const address="sheet!A4"
                 var comment = wb.comments.getItemByCell(address);
                 comment.delete();
                 wb.comments.add(address, "This is simple test comment");
               } catch (error) {
                 if (error.code == Excel.ErrorCodes.itemNotFound) {
                   wb.comments.add(address, "This is simple test comment");
                   console.log("Add comment successfully!");
                 }
               }
             
           });
           await ctx.sync();
       });

在此处输入图像描述

4

1 回答 1

0

@KaranChokshi,抱歉,我刚刚注意到您的办公版本是 2016,它不支持评论 API。注释 API 从 API 集开始可用:ExcelApi 1.10,有关更多详细信息,请参阅 docs.microsoft.com/en-us/office/dev/add-ins/reference/...。或许你可以帮忙确认一下,UI 端也没有评论相关的功能。

还有一点是你可能需要将 await ctx.sync() 移动到 try{},然后你可以按预期捕获详细错误(你的快照没有错误显示):

try {
const address="sheet!A4"
var comment = wb.comments.getItemByCell(address);
comment.delete();
 wb.comments.add(address, "This is simple test comment");
await ctx.sync();
} catch (error) {
if (error.code == Excel.ErrorCodes.itemNotFound) {
wb.comments.add(address, "This is simple test comment");
console.log("Add comment successfully!");
}

如果有任何其他问题,请告诉我。

于 2021-11-15T12:56:33.583 回答