Compartir a través de


ExcelScript.CommentRichContent interface

Representa el contenido contenido en una respuesta de comentario o comentario. El contenido enriquecido incita a la cadena de texto y a cualquier otro objeto contenido en el cuerpo del comentario, como las menciones.

Propiedades

mentions

Matriz que contiene todas las entidades (por ejemplo, personas) mencionadas en el comentario.

richContent

Especifica el contenido enriquecido del comentario (por ejemplo, el contenido del comentario con menciones, la primera entidad mencionada tiene un atributo id. de 0 y la segunda entidad mencionada tiene un atributo id. de 1).

Detalles de las propiedades

mentions

Matriz que contiene todas las entidades (por ejemplo, personas) mencionadas en el comentario.

mentions?: CommentMention[];

Valor de propiedad

richContent

Especifica el contenido enriquecido del comentario (por ejemplo, el contenido del comentario con menciones, la primera entidad mencionada tiene un atributo id. de 0 y la segunda entidad mencionada tiene un atributo id. de 1).

richContent: string;

Valor de propiedad

string

Ejemplos

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