Class: CommentManager

Core.SpreadsheetEditor. CommentManager


new CommentManager()

Methods


addComment(message, commentOptions)

Creates a new comment anchored to a single cell in the spreadsheet. This is only available when in Spreadsheet Editor editing mode.
Parameters:
Name Type Description
message string The text content of the comment.
commentOptions object
Properties
Name Type Argument Description
sheetName string The exact name of the sheet containing the cell, case sensitive.
cellString string A single-cell reference in A1 notation (e.g. "B3"). Range strings are not accepted.
author string <optional>
The author name. Defaults to the current user, or "Guest" if no current user is set.
Throws:
  • If the arguments are invalid.
    Type
    Error
  • If the spreadsheet editor is in view-only mode.
    Type
    Error
  • If the sheet or cell cannot be found.
    Type
    Error
  • If the comment cannot be created.
    Type
    Error
Returns:
The newly created comment.
Type
Core.SpreadsheetEditor.SpreadsheetComment
Example
WebViewer(...)
  .then(instance => {
    const { documentViewer, SpreadsheetEditor } = instance.Core;
    const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
    const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;

    spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
      const commentManager = spreadsheetEditorManager.getCommentManager();
      const comment = commentManager.addComment('This is a comment.', {
        sheetName: 'Sheet1',
        cellString: 'A1',
        author: 'Guest',
      });

      console.log(comment.getId());
    });
  });

addReply(parentId, message [, author])

Adds a reply to an existing spreadsheet comment.
Parameters:
Name Type Argument Description
parentId string The parent comment id.
message string The reply text.
author string <optional>
The author name. Defaults to the current user, or "Guest" if no current user is set.
Throws:
  • If the arguments are invalid.
    Type
    Error
  • If the spreadsheet editor is in view-only mode.
    Type
    Error
  • If the parent comment ID does not exist in the document.
    Type
    Error
  • If the reply cannot be created.
    Type
    Error
Returns:
The newly created reply comment.
Type
Core.SpreadsheetEditor.SpreadsheetComment
Example
WebViewer(...)
  .then(instance => {
    const { documentViewer, SpreadsheetEditor } = instance.Core;
    const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
    const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;

    spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
      const commentManager = spreadsheetEditorManager.getCommentManager();
      const comment = commentManager.getComments()[0];
      const replyMessage = 'Looks good to me';
      const author = 'Guest';

      if (comment) {
        const reply = commentManager.addReply(comment.getId(), replyMessage, author);
        console.log(reply.getParentComment().getId());
      }
    });
  });

deleteComment(commentId)

Deletes a comment or reply in a Spreadsheet Editor document.
Parameters:
Name Type Description
commentId string Unique identifier of the comment or reply.
Throws:
  • If the argument is invalid.
    Type
    Error
  • If the spreadsheet editor is in view-only mode.
    Type
    Error
  • If the comment or reply ID does not exist in the document.
    Type
    Error
  • If the comment or reply cannot be deleted.
    Type
    Error
Returns:
Type
void
Example
WebViewer(...)
  .then(instance => {
    const { documentViewer, SpreadsheetEditor } = instance.Core;
    const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
    const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;

    spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
      const commentManager = spreadsheetEditorManager.getCommentManager();
      const comment = commentManager.getComments()[0];
      if (comment) {
        commentManager.deleteComment(comment.getId());
      }
    });
  });

getComments()

Returns the comments in the current spreadsheet.
Returns:
The comments in the current spreadsheet.
Type
Array.<Core.SpreadsheetEditor.SpreadsheetComment>
Example
WebViewer(...)
  .then(instance => {
    const { documentViewer, SpreadsheetEditor } = instance.Core;
    const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
    const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;

    spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
      const commentManager = spreadsheetEditorManager.getCommentManager();
      const comments = commentManager.getComments();
      console.log(`Found ${comments.length} comment(s)`);
    });
  });

setCommentMessage(commentId, message)

Sets the message of a comment or reply in spreadsheet editor. Editing a comment in the resolved state reopens it before updating its message. This is only available when in Spreadsheet Editor editing mode.
Parameters:
Name Type Description
commentId string The ID of the target comment.
message string The replacement message content.
Throws:
  • If the arguments are invalid.
    Type
    Error
  • If the spreadsheet editor is in view-only mode.
    Type
    Error
  • If the comment ID does not exist in the document.
    Type
    Error
  • If the comment message cannot be updated.
    Type
    Error
Returns:
The updated comment or reply.
Type
Core.SpreadsheetEditor.SpreadsheetComment
Example
WebViewer(...)
  .then(instance => {
    const { documentViewer, SpreadsheetEditor } = instance.Core;
    const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
    const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;

    spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
      const commentManager = spreadsheetEditorManager.getCommentManager();
      const comment = commentManager.getComments()[0];
      if (comment) {
        const updatedComment = commentManager.setCommentMessage(comment.getId(), 'Updated comment text.');
        console.log(updatedComment.getMessage());
      }
    });
  });

setCommentState(commentId, state)

Sets the state of a spreadsheet comment and all of its replies. The specified ID may identify either the comment or one of its replies. This is only available when in Spreadsheet Editor editing mode.
Parameters:
Name Type Description
commentId string The ID of the comment or any of its replies.
state Core.SpreadsheetEditor.SpreadsheetCommentState The requested state.
Throws:
  • If the arguments are invalid or the comment cannot be found.
    Type
    Error
  • If the spreadsheet editor is in view-only mode.
    Type
    Error
  • If the comment state cannot be updated.
    Type
    Error
Returns:
Type
void
Example
WebViewer(...)
  .then(instance => {
    const { documentViewer, SpreadsheetEditor } = instance.Core;
    const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
    const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;

    spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
      const commentManager = spreadsheetEditorManager.getCommentManager();
      const comment = commentManager.getComments()[0];
      const state = SpreadsheetEditor.SpreadsheetCommentState.RESOLVED;
      if (comment) {
        commentManager.setCommentState(comment.getId(), state);
      }
    });
  });