You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Google Docs中超过20条的评论导出到Google Sheets

问题:Google Docs评论导出仅获取最近20条,旧评论无法导出

问题背景

此前实现了一个程序,可将指定Google Docs中的评论导出至指定Google Sheets,用于集中查看。单人使用时运行正常,但多人协作场景下,仅能导出最近20条评论,更早的评论无法导出,严重阻碍项目推进。

当前使用代码

function onOpen() {
  const ui = DocumentApp.getUi();
  ui.createMenu('Custom Functions')
      .addItem('Export Comments to Google Sheets', 'listComments')
      .addToUi();
}

function listComments() {
  // Initialize Variables
  var docId = '1h-BJrklSFgfGNCzdAWziNx5b5EDRjHHJ3DTkXHNhtUE'; 
  var comments = Drive.Comments.list(docId);
  var sList = [], hList = [], cList = [], nList = [], dList = [];

  // 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 
      sList.unshift([comment.status]);
      hList.unshift([comment.context.value]);
      cList.unshift([comment.content]);
      nList.unshift([comment.author ? comment.author.displayName : '']);
      dList.unshift([comment.createdDate ? new Date(comment.createdDate).toLocaleString() : '']);
    }
    // Update spreadsheet values 
    var sheet = SpreadsheetApp.openById('1XNJdSRMB1KR9_gpzbd6_rIC6WYpPoExuWkb12Nd1tRI').getSheetByName('Comments');
    sheet.getRange("A2:A" + (sList.length + 1)).setValues(sList);
    sheet.getRange("B2:B" + (hList.length + 1)).setValues(hList);
    sheet.getRange("C2:C" + (cList.length + 1)).setValues(cList);
    sheet.getRange("D2:D" + (nList.length + 1)).setValues(nList);
    sheet.getRange("E2:E" + (dList.length + 1)).setValues(dList);
  }
}

注:该程序需添加“Drive API (V2)”服务以访问Google Drive文件。

已尝试的排查动作

  • 删除旧评论后重新添加,未解决问题
  • 尝试切换至Drive API V3,但运行后无评论导出,从Google Docs自定义菜单运行时触发错误:GoogleJsonResponseException: API call to drive.comments.list failed with error: The 'fields' parameter is required for this method

请求

恳请提供其他排查及解决思路

内容的提问来源于stack exchange,提问作者Robert Wenger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 16:15:35