0

My requirement was to add notes to cells in Excel using OfficeJS.

However since Microsoft confirmed that adding notes using OfficeJS is not possible in the current version, as a workaround I am trying to use the Comments feature.

I could add comments with status as resolved.

Resolved Comments

However I want to disable/ hide the Reopen thread and Delete thread so that the user cant make any changes to the comment and also remove the timestamp in the comment.

This would make the comments behave somewhat similar to Notes.

Here is my code for adding resolved comments.

async function addCellComment(){
  await Excel.run(async (context) => {
    let comments = context.workbook.comments;
    let cell = context.workbook.getActiveCell();
    cell.load("address");
    await context.sync();
    comments.add(cell.address, "This is "+ cell.address);
    let commentThreadCount = context.workbook.comments.getCount();
    context.workbook.comments.load("getCount");
    await context.sync();
    for(let i = 0; i < commentThreadCount.value;i++){
        context.workbook.comments.getItemAt(i).resolved = true;
    }
    
});
}
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
WorksOnMyLocal
  • 1,617
  • 3
  • 23
  • 44
  • Have you tried calling the `context.sync` method after? Does it help? Do you get any errors at runtime? – Eugene Astafiev Jun 13 '23 at 11:10
  • The code above works fine. All I did was to loop through all the comment threads in the workbook and mark them resolved so that there is no option for reply(as shown in the image). But the User can still reopen the thread and use the reply textbox. So I want to hide/disable the 'Reopen thread' button. – WorksOnMyLocal Jun 13 '23 at 11:21

1 Answers1

0

To delete a comment use the Comment.delete method. Deleting a comment also deletes the replies associated with that comment.

await Excel.run(async (context) => {
    // Delete the comment thread at A2 on the "MyWorksheet" worksheet.
    context.workbook.comments.getItemByCell("MyWorksheet!A2").delete();
    await context.sync();
});

A comment thread has a configurable boolean value, resolved, to indicate if it is resolved. A value of true means the comment thread is resolved. A value of false means the comment thread is either new or reopened.

Read more about the available methods and properties for comments in the Office JavaScript API in the Work with comments using the Excel JavaScript API article.

Note, you can post or vote for an existing feature request on Tech Community where they are considered when the Office dev team goes through the planning process.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • I appreciate your response, but you probably did not understand my requirement correctly. I dont want to delete the comment, instead I want to remove the 'Delete thread' and 'Reopen thread' buttons when the comment is already resolved. As you can see in my OP I've already resolved the thread using the 'resolved' property. But I dont want the user to again re-open,edit or delete the comment. – WorksOnMyLocal Jun 15 '23 at 04:52
  • The Office JavaScript API doesn't provide anything for that. Try to post a feature request for that using the link mentioned in my post. – Eugene Astafiev Jun 15 '23 at 08:31