将 Google 文档评论导出到 Google 表格,以及突出显示的文本?

Export Google Docs comments into Google Sheets, along with highlighted text?

是否可以从 Google Docs 导出评论,以便评论显示在 Google Sheets 文档的一栏中,并突出显示来自 Google Doc 的文本显示在它旁边的列中?

我知道可以通过 API:

访问文件注释

https://developers.google.com/drive/v3/reference/comments#methods

但是我们可以用它来提取文档的注释和突出显示的文本吗?任何帮助将不胜感激。

首先在服务下添加Drive API

然后试试这个:

代码:

function listComments() {
  // Change docId into your document's ID
  // See below on how to
  var docId = '1fzYPRldd16KjsZ6OEtzgBIeGO8q5tDbxaAcqvzrJ8Us'; 
  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.getActiveSheet();
    sheet.getRange("A1:A" + hList.length).setValues(hList);
    sheet.getRange("B1:B" + cList.length).setValues(cList);
  }
}

文件:

输出:

资源:

  • Access Google docs comments from Google app scripts
  • Document ID