0

I am trying to copy a Google Sheet while retaining all the comments (which are associated with cells), following this.

Everything works fine until the line Drive.Comments.insert(item, documentId).commentId

An error saying:

Anchor is missing required property root.r`

appeared.

Has anyone tried doing so, and could you enlighten me on what's wrong?

My attempt

  1. I tried to look deeper into the Google Drive APIs, the example they gave is only for "document-level comment", and allows no where for the anchor to be input.

  2. The second answer here claims that it is impossible to attach programmatically the comment to a cell, because the anchors for Spreadsheet Comments are proprietary. This seems to contradict with the first link (unless the first link only talks about document wide comments)

  3. Seems like setting comments in Google Sheet have been requested for a long time, yet it hasn't been implemented. (here and here) So using the Drive API seems to be the only way to insert comment.

Any help is highly appreciated!

Kos
  • 4,890
  • 9
  • 38
  • 42
Matthew
  • 369
  • 3
  • 17
  • 1
    I'm really sorry for the inconvenience. [This sample script](https://stackoverflow.com/questions/50877531/script-for-a-google-doc-makecopy-the-comments-arent-copied) is for Google Document. In the case of Spreadsheet, such error occurs because the value of ``anchor`` is not parsed. – Tanaike Aug 05 '18 at 03:35
  • 1
    In order to remove this error, there are 2 patterns. 1. Put ``item.anchor = JSON.parse(item.anchor)`` before ``var commentId =``. 2. Put ``delete item.anchor`` instead of ``item.anchor = JSON.parse(item.anchor)``. Unfortunately, ``anchor`` retrieved from the source Spreadsheet cannot be used for the destination one. I'm not sure about the reason. So ``delete item.anchor`` instead of ``item.anchor = JSON.parse(item.anchor)`` can be also used. I'm really sorry for my incomplete answer. – Tanaike Aug 05 '18 at 03:35
  • Please don't apologize! Your answer has been immensely helpful! By "`anchor` retrieved from the source Spreadsheet cannot be used for the destination one", do you mean we cannot put the comments to exactly the same cell? Maybe it's because of the proprietary nature of the anchor mentioned in the second answer's link? Do you think there is any workaround about it? – Matthew Aug 05 '18 at 03:44
  • 1
    Although I have checked [this](https://developers.google.com/drive/api/v3/manage-comments) and try several objects for the anchor, they couldn't be used. Also it seems that [this thread](https://stackoverflow.com/questions/23498275/creating-anchored-comments-programmatically-in-google-docs) is the same situation with this. I thought that putting a comment using a created anchor to Spreadsheet might not be able to be done yet. About this, if I found the solution or workaround, I would like to report. I'm really sorry. – Tanaike Aug 05 '18 at 04:44
  • 1
    @Tanaike No problem! Thanks a lot again for your response! – Matthew Aug 05 '18 at 05:20

0 Answers0