-1

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

  • replace image with text. What is that garbage in the catch section? are you sure it works at all? – david Nov 12 '21 at 07:11
  • Yes, I am double sure that all functionality is working fine in web office 365 and Mac system office however the add-in is properly loaded in the Windows system excel app but when I click on the save map button and try to insert or load comment in the cell it is not working. – Karan Chokshi Nov 12 '21 at 08:44
  • @KaranChokshi, may I know the detail error? or it's just no response? I cannot repro the issue at my local. My Excel build version is: 14701.20060 – ginger jiang Nov 12 '21 at 09:36
  • @gingerjiang there is no error I got, however, the comment is not mapping on the cells in the Windows system office. can you please see the attached screenshot. – Karan Chokshi Nov 12 '21 at 11:33
  • @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 https://learn.microsoft.com/en-us/office/dev/add-ins/reference/requirement-sets/excel-api-requirement-sets for more details. And maybe you can help to double confirm, the UI side also didn't has comments related features. – ginger jiang Nov 15 '21 at 05:20
  • And another point is that you may need to move the await ctx.sync() to the try{}, then you can catch the error: – ginger jiang Nov 15 '21 at 12:51

1 Answers1

0

@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.