1

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.

Joniek
  • 11
  • 1
  • 2

3 Answers3

10

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 :

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

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • How to display datepicker by double click on specific column using rest API? – Parthiv Jul 05 '18 at 11:16
  • @kpp I couldn't understand the meaning of your comment. I'm really sorry. If there are some issues in my answer, please tell me. I would like to modify it. – Tanaike Jul 05 '18 at 11:36
  • "Note" and "Comment' have 2 very different ways of presenting information, so they are not the same (you can't show multiple hyperlinks in note, but you can in comments) – Starwave Aug 12 '19 at 08:40
  • @Starwave Thank you for your comment. Yes. I know it. So I also had answered about it. But I have to apologize for my poor English skill. – Tanaike Aug 13 '19 at 00:22
  • Thank you @Tanaike, let me ask you this. I looked at the API to find out what `field` means (https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#UpdateCellsRequest). They talk about the `FieldMask` which I do not understand how it maps with the `notes` field in the payload above. My spreadsheet has no `notes` field, but the API call succeeded and added a note. What all possible values `fields` can contain? Is there a reference documentation available? – daydreamer Aug 15 '19 at 14:05
  • Also, I do agree with @Starwave, that notes and comment are 2 different things. – daydreamer Aug 15 '19 at 14:06
  • @daydreamer Thank you for your comment. Unfortunately, I cannot understand about the situation of your question. Can I ask you about the detail? I apologize for my poor English skill. – Tanaike Aug 15 '19 at 23:24
  • @daydreamer Thank you for your comment. Yes. I know it. So I also had answered about it. But I have to apologize for my poor English skill again. – Tanaike Aug 15 '19 at 23:24
  • You are awesome, @Tanaike, don't apologize! – daydreamer Aug 16 '19 at 00:07
  • @daydreamer Thank you for replying. About your question, I would like to know it. Could you provide more information of it? – Tanaike Aug 16 '19 at 00:29
  • Other than `note` what other values could be used in the `field`? – daydreamer Aug 16 '19 at 00:53
  • @daydreamer Thank you for replying. I apologize for my poor English skill. I cannot understand about `Other than note what other values could be used in the field?`? I cannot see the vision of your goal. – Tanaike Aug 16 '19 at 01:06
  • I'll try again. In the payload you mentioned to use `note` for `fields` key, right? I am asking what all possible value `fields` can have other than `note`? – daydreamer Aug 16 '19 at 22:35
  • @daydreamer Thank you for your explanation. When a note is put to a cell using updateCells of Sheets API, you want to know whether the values except for `note` can be used to `fields`. I could understand like this. Is my understanding correct? – Tanaike Aug 16 '19 at 23:27
  • Hi @Tanaike, thanks for the answer. I saw your great list and it seems you have explored Google Service APIs in depth. I just want to ask if there's any way of leaving a comment on a Google spreadsheet cell via Google Sheets API? Thanks!! – Gaurav Sachdeva Sep 26 '19 at 15:05
  • @Gaurav Sachdeva Thank you for your comment. Unfortunately, in the current stage, the comments can be put by only Drive API. If you put the notes to the Spreadsheet, you can do it using Sheets API. – Tanaike Sep 26 '19 at 22:10
  • Can I put comments to Google Spreadsheet using Google Drive API? I tried to add comment via https://developers.google.com/drive/api/v3/manage-comments but the comment is added on the page and not on the cell. Thanks! – Gaurav Sachdeva Sep 27 '19 at 06:35
  • 1
    @Gaurav Sachdeva Is this information useful for your situation? https://stackoverflow.com/q/57511838 – Tanaike Sep 27 '19 at 11:57
  • 1
    Yes @Tanaike, it's the same situation I am in. Thanks for pointing and confirming. – Gaurav Sachdeva Sep 28 '19 at 07:39
1

Old thread but hopefuly this helps to whoever is stuck.

            List<Request> requests = new ArrayList<>();
            requests.add(new Request().setRepeatCell(new RepeatCellRequest()
                    .setRange(new GridRange()
                            .setSheetId(**SHEET NUMERIC ID**)
                            .setStartRowIndex(0)
                            .setEndRowIndex(1)
                            .setStartColumnIndex(0)
                            .setEndColumnIndex(1)).setCell(new CellData().setNote("This is a note")).setFields("note")));
            BatchUpdateSpreadsheetRequest body = new BatchUpdateSpreadsheetRequest()
                    .setRequests(requests);



            this.mService.spreadsheets().batchUpdate(spreadsheetId, body).execute();

This will insert a note in A1 just replace sheet id with the numeric ID

0

Looks like we have the API for comments: https://developers.google.com/drive/api/v3/manage-comments

user2301299
  • 529
  • 1
  • 5
  • 15