1

I'm a language teacher, and I often share documents with students and ask them to highlight new words. During the classes, I often make comments with the definitions of the words and other info.

I thought it would be way more efficient if I found some way to extract the highlights and comments directly into Google Sheets (I want the students to be able to easily make flashcards using Anki).

I found another StackOverflow post about a way to write a script to do this, but I can't seem to get it to work. Here's the message I get when trying to run it:

TypeError

function listComments() { 
  // Change docId into your document's ID 
  // See below on how to 
  var docId = 'doccode'; 
  var comments = Drive.Comments.list(docId); 
  var hList = [], cList = []; 
  
  // Get list of comments 
  if (comments.items && comments.items.length > 0) { 
    for (var i = 0; i < comments.items.length; i++) { 
      var comment = comments.items[i]; 
      // add comment and highlight to array's first element 
      hList.unshift([comment.context.value]);
      cList.unshift([comment.content]);
    }
    // Set values to A and B
    var sheet = SpreadsheetApp.getActiveSpreadsheet();
    sheet.getRange("A1:A" + hList.length).setValues(hList);
    sheet.getRange("B1:B" + cList.length).setValues(cList);
  }
}

There's a TypeError with the "getRange" property, and I'm not sure what to change. (Sorry, almost completely new to coding, so it's probably an obvious answer!)

Any help is appreciated!

Rubén
  • 34,714
  • 9
  • 70
  • 166
Joey D.
  • 11
  • 2
  • 1
    It seems your script isn't container bound, ie., you created it from the Script home screen, rather than from a spreadsheet. If that's the case, you would have to open the sheet first with `let sheet = SpreadsheetApp.openById("");` – johndee31415 Aug 21 '22 at 11:25

0 Answers0