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

如何查询Google Sheets文件所有者及处理评论的用户名?

获取Google Sheets文件所有者及评论处理用户的方法

获取文件所属用户名

  • 借助Google Apps Script调用Drive API实现:通过DriveApp.getFileById(fileId).getOwner()方法获取所有者对象,再用getEmail()拿到关联邮箱(即用户名标识),如果需要显示名称,调用getDisplayName()即可。
  • 注意事项:运行脚本时需要授权Drive访问权限;若文件属于企业域,需确认域内权限是否允许获取所有者信息。

获取处理评论的用户名称

Google Sheets中已处理(标记为已解决)的评论,可通过Apps Script的评论接口获取处理者信息:

  • 核心逻辑:通过SpreadsheetApp.getActiveSpreadsheet().getComments()获取所有评论,对已解决的评论调用getResolvedBy()拿到处理用户对象,再提取邮箱或显示名。
  • 示例代码:
function getResolvedCommentHandlers() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const allComments = ss.getComments();
  allComments.forEach(comment => {
    if (comment.isResolved()) {
      const handler = comment.getResolvedBy();
      console.log(`处理评论的用户:${handler.getDisplayName()}(邮箱:${handler.getEmail()})`);
    }
  });
}
  • 注意:未标记为已解决的评论,getResolvedBy()会返回null,无法获取处理者信息。

内容的提问来源于stack exchange,提问作者Neta Bashari

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 11:25:19