Excel Add In Can't Add Comments - This operation is not implemented.

Arnav Garg 0 Reputation points
2024-06-24T20:43:20.21+00:00

Trying to add comments programatically to Excel through my add in, but getting "this operation is not implemented" error every time.

Code for reference (in taskpane.js):

function comment(text) {
  Excel.run(async context => {
    const range = context.workbook.getSelectedRange();
    range.values = [[text]];
    

    let comments = context.workbook.comments;

    // Note that an InvalidArgument error will be thrown if multiple cells passed to `Comment.add`.
    comments.add(range, "TODO: add data.");

    await context.sync();
    logMessage('Text inserted into Excel');
  }).catch(error => {
    logMessage(`Error inserting text into Excel: ${error.message}`);
  });
}

Alternatively, are there any other ways to add metadata about a cell to store info? The only reason I'm trying to make a comment is so that I can store information about the cell and later access it in my taskpane, but is there a form of metadata or something I can programatically access through my taskpane instead of a comment?

Also worth noting I just followed the code suggested in Excel API docs: https://video2.skills-academy.com/en-us/office/dev/add-ins/excel/excel-add-ins-comments

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,646 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,680 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yue Li 0 Reputation points Microsoft Employee
    2024-07-02T08:22:22.0366667+00:00

    Hi Arnav, I built an Excel Add-in locally and it's working well. Here is my taskpane.js code. You can copy it and try to it. Hope it helps you! Thanks! :)

    export async function run() {
      try {
        await Excel.run(async context => {
          const range = context.workbook.getSelectedRange();
          // range.values = [[text]];
          
          let comments = context.workbook.comments;
      
          // Note that an InvalidArgument error will be thrown if multiple cells passed to `Comment.add`.
          comments.add(range, "TODO: add data.");
      
          await context.sync();
          console.log('Text inserted into Excel');
        });
      } catch (error) {
        console.error(`Error inserting text into Excel: ${error.message}`);
      }
    }
    

    User's image

    0 comments No comments