Insert a comment in a Google Sheet with google-she

2020-03-08 07:33发布

问题:

Is it possible to add a comment to a cell in a Google Sheet using Google Sheet API ? I have searched https://developers.google.com/sheets/api/, but found no command that does this.

回答1:

Yes. You can add a comment to a cell. But "comment" is used as "note" at Sheets API. You can add "note" using spreadsheets.batchUpdate of Sheets API.

The endpoint and sample request body is as follows.

Endpoint :

POST https://sheets.googleapis.com/v4/spreadsheets/### Spreadsheet ID ###:batchUpdate

Sample request body :

{
  "requests": [
    {
      "updateCells": {
        "range": {
          "sheetId": ### sheetId ###,
          "startRowIndex": 0,
          "endRowIndex": 1,
          "startColumnIndex": 0,
          "endColumnIndex": 1
        },
        "rows": [
          {
            "values": [
              {
                "note": "sample note"
              }
            ]
          }
        ],
        "fields": "note" // You can also use ``*``.
      }
    }
  ]
}

Note :

  • Please add the cell coordinates as GridRange.
  • "startRowIndex": 0, "endRowIndex": 1, "startColumnIndex": 0, "endColumnIndex": 1 is "A1".

Reference :

  • CellData
  • GridRange

If this was not what you want, I'm sorry.