【问题标题】:Export Google Docs comments into Google Sheets, along with highlighted text?将 Google 文档评论以及突出显示的文本导出到 Google 表格中?
【发布时间】:2021-05-12 04:01:14
【问题描述】:

是否有一种方法可以从 Google Docs 导出 cmets,以便 cmets 显示在 Google Sheets 文档中的一列中,而 Google Doc 中突出显示的文本显示在旁边的列中?

我了解文件 cmets 可通过 API 访问:

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

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

【问题讨论】:

  • 我已经编辑了我的答案,将 sheet 的设置值放在 if 块语句中,以防止在没有突出显示的文本时出错。你可能想检查一下。

标签: google-apps-script google-sheets google-docs data-extraction


【解决方案1】:

首先在服务下添加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);
  }
}

文档:

输出:

资源:

【讨论】:

  • 感谢您的帮助。它确实有效。
  • 嗨@Roomi,很高兴它成功了。如果您的问题得到解决,请按接受按钮。与您有相同问题的其他人也可以将您的问题作为可以解决的问题。如果找不到按钮,请随时告诉我。 stackoverflow.com/help/accepted-answer
猜你喜欢
  • 1970-01-01
  • 2015-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-29
  • 1970-01-01
  • 2014-04-15
相关资源
最近更新 更多