Freigeben über


ExcelScript.CommentRichContent interface

Stellt den Inhalt dar, der in einem Kommentar oder einer Kommentarantwort enthalten ist. Umfangreiche Inhalte enthalten die Textzeichenfolge und alle anderen Objekte, die im Kommentartext enthalten sind, z. B. Erwähnungen.

Eigenschaften

mentions

Ein Array, das alle Entitäten (z. B. Personen) enthält, die im Kommentar erwähnt werden.

richContent

Gibt den umfangreichen Inhalt des Kommentars an (z. B. Kommentarinhalt mit Erwähnungen, die erste erwähnte Entität hat das ID-Attribut 0 und die zweite erwähnte Entität hat das ID-Attribut 1).

Details zur Eigenschaft

mentions

Ein Array, das alle Entitäten (z. B. Personen) enthält, die im Kommentar erwähnt werden.

mentions?: CommentMention[];

Eigenschaftswert

richContent

Gibt den umfangreichen Inhalt des Kommentars an (z. B. Kommentarinhalt mit Erwähnungen, die erste erwähnte Entität hat das ID-Attribut 0 und die zweite erwähnte Entität hat das ID-Attribut 1).

richContent: string;

Eigenschaftswert

string

Beispiele

/**
 * 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
      );
    }
  }
}