ExcelScript.CommentRichContent interface

Represents the content contained within a comment or comment reply. Rich content incudes the text string and any other objects contained within the comment body, such as mentions.

Properties

mentions

An array containing all the entities (e.g., people) mentioned within the comment.

richContent

Specifies the rich content of the comment (e.g., comment content with mentions, the first mentioned entity has an ID attribute of 0, and the second mentioned entity has an ID attribute of 1).

Property Details

mentions

An array containing all the entities (e.g., people) mentioned within the comment.

mentions?: CommentMention[];

Property Value

richContent

Specifies the rich content of the comment (e.g., comment content with mentions, the first mentioned entity has an ID attribute of 0, and the second mentioned entity has an ID attribute of 1).

richContent: string;

Property Value

string

Examples

/**
 * This sample finds overdue work items in a table and 
 * lets their owners know with a comment that uses an @mention.
 * 
 * This assumes the worksheet has a table with the columns: 
 * "Work Item", "Project", "Owner", "Due Date"
 */
function main(workbook: ExcelScript.Workbook) {
  let currentSheet = workbook.getActiveWorksheet();

  // Get the "Owner" column range and values.
  let table = currentSheet.getTables()[0];
  let ownerColumnRange = table.getColumn("Owner").getRangeBetweenHeaderAndTotal();
  let ownerColumnValues = ownerColumnRange.getValues();

  // Get the "Due Date" column range and values.
  let dueDateColumnRange = table.getColumn("Due Date").getRangeBetweenHeaderAndTotal();
  let dueDateColumnValues = dueDateColumnRange.getValues();

  // Look for overdue work items.
  for (let row = 0; row < dueDateColumnValues.length; row++) {

    /* Convert the Excel date into a JavaScript date. 
     * This is necessary because Excel and JavaScript store
     * their dates as different numerical values.
     */
    let dueDate = new Date(Math.round((dueDateColumnValues[row][0] as number - 25569) * 86400 * 1000));

    // Check if the current date is greater than the due date.
    if (Date.now() > dueDate.valueOf()) {

      /* Create a CommentMention object for the comment,
       * based on the work item's owner.
       *
       * A CommentMention's properties are:
       * `name`: The name of the person being mentioned.
       * `id`: The index of this mention in the comment.
       * `email`: The email address of the person being mentioned. 
       *          In this sample, "Owner: is also the user name for the email.
       */
      let mention = {
        name: ownerColumnValues[row][0].toString(),
        id: 0,
        email: ownerColumnValues[row][0] + "@contoso.com"
      };

      /* Create the comment. 
       * The `<at id="0">` syntax embeds the mention in the comment text. 
       * The name is displayed in the comment, 
       * while an email is sent to the given address.
       *
       * The addComment parameters are:
       * `cellAddress`: The location of the comment.
       * `content`: The text of the comment and any embedded mentions.
       * `contentType`: The type of comment ("Mention" or "Plain").
       */
      currentSheet.addComment(
        dueDateColumnRange.getCell(row, 0),
        {
          richContent: '<at id="0">' + mention.name + "</at> - Your work item is overdue.",
          mentions: [mention]
        },
        ExcelScript.ContentType.mention
      );
    }
  }
}