ChemMitch's avatar
ChemMitch
Brass Contributor
Dec 29, 2023
Status:
New

Add support for 'Notes' to Office JS API for Excel

I'm migrating a VSTO Excel add-in to JS and noticed a features that's not available yet.


In the VSTO model, we can create cell comments/notes that are intended as documentation, showing the user the purpose of a column within a spreadsheet. This differs from the philosophy of comments with Office JS - as a dialog between users.
The following comment from a sheet created by the VSTO add-in shows what I mean:

 

 

In JS

 

 

the comment 1) includes the user's name which is not relevant here
2) invites replies, which we don't want here.
(I've figured out how to mark a comment as resolved but it still does not look as nice.)

 

Also, in VSTO, we can add images to comments. This is very useful when communicating chemistry within an Excel sheet -- the chemical structure conveys lots information but can be obtrusive. In a comment, the structure appears when the user hovers over the cell.

 

This is a request to add these capabilities to Office JS.

7 Comments

  • ChemMitch's avatar
    ChemMitch
    Brass Contributor

    Great news indeed!

    Is there an example of how to add a Note to a cell?

    • AdrianWu's avatar
      AdrianWu
      Icon for Microsoft rankMicrosoft

      No problem! You can try the following code snippet:

      async function run() {
        try {
          await Excel.run(async (context) => {
            // Get the currently active worksheet
            const sheet = context.workbook.worksheets.getActiveWorksheet();
      
            // Get the current note count
            const noteCountBefore = sheet.notes.getCount();
            await context.sync();
            console.log("Notes before:", noteCountBefore.value);
      
            // Add a note to cell A1
            const expectedContent = "This is a test note.";
            const note = sheet.notes.add("A1", expectedContent);
            await context.sync();
      
            // Load and display the note details
            note.load(["content", "authorName"]);
            await context.sync();
            console.log("Note author:", note.authorName);
            console.log("Note content:", note.content);
      
            // Verify the note count increased
            const noteCountAfter = sheet.notes.getCount();
            await context.sync();
            console.log("Notes after addition:", noteCountAfter.value);
          });
        } catch (error) {
          console.error("Error:", error);
        }
      }

      Hope this is helpful!

  • HI ChemMitch, tobydimmick 

    I’m excited to share some great news: the Note API is now supported in the latest Excel API set (v1.18), which applies to all Excel endpoints—including Web, Windows, and Mac.

    Please check here for more details:
    https://learn.microsoft.com/en-us/javascript/api/excel/excel.note?view=excel-js-preview

    Regarding the unintended behavior of comments unnecessarily including user names, this is also the default behavior for notes. After any user input, Excel automatically adds the author's name to the top of the note. However, developers can manually edit the note again to remove it if necessary. We will continue to improve the Note API to enhance the developer experience, but we hope this update already helps unblock your add-in development.

  • tobydimmick's avatar
    tobydimmick
    Copper Contributor

    This seems like a very basic feature considering comments are already implemented, unless notes are more complex than I'm aware. We're rewriting an addin from COM framework to Office.js, and we need access to read/write notes in order to maintain compatibility and feature parity.

  • bbirkelund470's avatar
    bbirkelund470
    Copper Contributor

    We would like to do this aswell, we want to show a user where the info from a cell came from, and this is best done with a note programatically.

  • kenlin's avatar
    kenlin
    Copper Contributor

    We too would like the ability to create Notes for cells and columns for the JavaScript Excel Add-in we provide our customers which creates tables for them to reference.  Providing Notes for the column heading cells allows us to add descriptions for each of the columns, rather than forcing our customers to access our help pages.

    We are currently using https://learn.microsoft.com/en-us/office/dev/add-ins/excel/excel-add-ins-comments, which suffers from the drawbacks ChemMitch mentioned above.

  • crcastle's avatar
    crcastle
    Copper Contributor

    I would also like the ability to add a note to a cell. I want to provide more context to the user about the value returned by a custom function. For example they used a custom function to request the Market Cap of MSFT on 12/31/23, but 12/31/23 was not a trading day, so the function has returned the Market Cap of MSFT on 12/29/23, the last trading day before 12/31/23.

     

    It would be great to be able to use something like the https://learn.microsoft.com/en-us/javascript/api/excel/excel.formattednumbercellvalue?view=excel-js-preview, https://learn.microsoft.com/en-us/javascript/api/excel/excel.cellvalueattributionattributes?view=excel-js-preview, or https://learn.microsoft.com/en-us/javascript/api/excel/excel.cellvalueproviderattributes?view=excel-js-preview interfaces. For example a `note` property to attach a note to the cell when the function returns a value to the cell.