Why does window System dynamic comment is not work in excel?

101 views Asked by At

I am working with office js. my add-in inserts a comment in the cell that is working properly with mac system office and office 365 but I can't insert comments in the windows system office. the version of office 2016. what did I do wrong? Please guide me thanks.

Here is my code snippet

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();
       });

enter image description here

1

There are 1 answers

2
ginger jiang On

@KaranChokshi, sorry I just noticed your office version is 2016, which hasn't supported comments API. The comments API are available since API set: ExcelApi 1.10, refer to learn.microsoft.com/en-us/office/dev/add-ins/reference/… for more details. And maybe you can help to double confirm, the UI side also didn't has comments related features.

And another point is that you may need to move the await ctx.sync() to the try{}, then you can catch the detail error as expected (your snapshot has no error shows):

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!");
}

Please let me know if have any other issues.