Google Apps Script Spreadsheet Comment Automation

前端 未结 3 1622
野性不改
野性不改 2020-11-27 20:00

Today I have a question about Google Apps Scripts, specifically for Spreadsheets. I\'ve already looked at the documentation here (yes, documentation on a Sheet<

相关标签:
3条回答
  • 2020-11-27 20:11

    Using Google Drive API in Google Apps Script, we could create Comments in a Google Document.
    And after a test, I confirm you can also do it in a Spreadsheet (which is normal because Comments depends only on Drive API)

    function insertDriveComment(fileId, comment, context) {
      var driveComment = {
        content: comment,
        context: {
          type: 'text/html',
          value: context
        }
      };
      Drive.Comments.insert(driveComment, fileId);  
    }
    

    Keep in mind that you cannot attach programmatically the comment to a cell (or to words in Google Document), because anchors for Document and Spreadsheet Comments are proprietary (check the video at the bottom of the page here)

    Hope it could help.

    0 讨论(0)
  • 2020-11-27 20:24

    There is no way to manipulate Comments via Spreadsheet Services - see Issue 36756650. (Star it if you wish.)

    Instead, all the "Comments" methods work on Notes.

    The following method will append a new "Modified" timestamp to any existing one - not quite as nice looking as an actual Comment would be, unfortunately.

    function onEdit() {
      var sheet = SpreadsheetApp.getActiveSpreadsheet();
      var cell = sheet.getActiveCell();
      var comments = cell.getComment();
      // Newline works in msgBox, but not in Note.
      comments = comments + "\\nModified: " + (new Date());
      //Browser.msgBox(comments);
      cell.setComment(comments);
    }
    
    0 讨论(0)
  • 2020-11-27 20:27

    Updated answer for dic 2018:

    Now Google supports the setNote(String) and setNotes(Object[]) method in the Range class.

    the getComment() and setComment() methods no longer exist.

    0 讨论(0)
提交回复
热议问题