在Google电子表格中获取编辑者姓名并将其写入单元格 [英] Fetch editors name in google spreadsheet and write it to cell

查看:120
本文介绍了在Google电子表格中获取编辑者姓名并将其写入单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以拥有一个onEdit函数,该函数可以获取编辑者姓名,并在A2更改时将其写入B2?

Is there any way to have an onEdit function that fetches the editors name and writes it to B2 whenever A2 is changed?

< a href = https://docs.google.com/spreadsheets/d/1hYp2KAZSlRN2HNUWvyHAkc35mJtDPBSVipl4PtrSIJw/edit?usp=sharing rel = nofollow> https://docs.google.com/spreadsheets/d/1hYp2KAZSlRN2HNUWvyPHA? usp = sharing

(例如,我的Google帐户的名称为 Thomas G.,因此应将其写入B2。)
可能吗?

(e.g, the name of my google account is "Thomas G.", so this should be written to B2.) Possible?

推荐答案

重要注意事项:以下代码通常仅在所有者/发布者有效的情况下有效脚本和访问工作表的用户属于相同的Google Apps域。它不适用于非应用程序用户。

IMPORTANT CAVEAT: the code below will generally work only if the owner/publisher of the script and the user accessing the sheet belong to the same Google Apps domain. It will NOT work for non-apps users.

您可以使用工作表中的以下onEdit()方法执行此操作:

You can do this with the following onEdit() method in your sheet:

function onEdit(e) {
  var editedRange = e.range;
  if ( editedRange.getColumn()==1 ) { // if column A was edited
    var u = Session.getActiveUser().getEmail();
    editedRange.offset(0, 1).setValue(u); // write user's email to corresponding row in column B
  }
};

注意:这将要求用户授权脚本访问其在Google上的数据(以了解用户的电子邮件)。

Note: this will require users to authorize the script's access to their data on Google (to know the user's email).

这篇关于在Google电子表格中获取编辑者姓名并将其写入单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆