为什么我的Google电子表格脚本无法在getUser()上捕获电子邮件? [英] Why is my Google spreadsheet script not capturing emails on getUser()?

查看:51
本文介绍了为什么我的Google电子表格脚本无法在getUser()上捕获电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Google表格上编写我的第一个Google Apps脚本,并为它打开的可能性感到非常兴奋.但是,我仍在尝试找出一些事情:例如在电子表格的不同标签之间以及跨独立电子表格(具有不同的电子表格ID)之间移动数据:有人可以建议如何做到这一点吗?

I'm writing my first Google apps script on google sheets and am pretty excited about the possibilities that it opens up. However, I'm still trying to figure out a few things: such as moving data between different tabs of a spreadsheet and across independent spreadsheets (with different spreadsheet Ids): Can someone suggest how this can be done?

但是我最关心的是,我的脚本正在捕获时间戳,但是我也希望它记录用户的电子邮件.我在文档中读到,有一个复杂的标准可以确定为什么可以捕获或不捕获电子邮件-该标准是什么?因为奇怪的是,在最初测试代码时,我自己的电子邮件被捕获了,但只发生在大约50%的情况下.我不确定我是否完全了解这里发生了什么?

But my immediate concern is that, my script is capturing timestamps but I also want it to record the emails of the users. I read in the docs that there is a complex criteria that determines why an email can be captured or not - what is that criteria? Because strangely while testing the code initially, the my own email was getting captured but only in about 50% of the cases. I'm not sure I understand entirely whats going on here?

我的代码:

function onEdit(e){
  // Set a comment on the edited cell to indicate when it was changed.
  var range = e.range;
  var activeSheet = e.source.getActiveSheet();
  range.setNote('Last modified: ' + new Date() + new Date().toLocaleTimeString() + ' sheet: ' + activeSheet.getName());
  if (activeSheet.getName() == "KYCEntrySheet"){
    var r = e.source.getActiveCell();
    if( r.getColumn() == 10 ) { //Any changes within this column set the date below and the email on the 2nd call
      //if( r.offset(0, 1).getValue() === '' ) //is empty?
        r.offset(0, 5).setValue(new Date().toLocaleTimeString());//will only put date, format "123/Date and time" if time needed
      //if( r.offset(0, 2).getValue() === '' ) //is empty?
        r.offset(0, 9).setValue(Session.getUser());//inserts current users email
    }}}

谢谢!

推荐答案

您不会收到未明确允许您知道其电子邮件的用户的电子邮件.例如,假设有人共享一个电子表格供所有人编辑,并使用onEdit触发器以不可见的方式收集其电子邮件. Google不允许发生这种情况.

You can't get emails of users that did not explicitly allow you to know their emails. For example, imagine someone sharing a spreadsheet for everyone to edit, and invisibly collecting their emails using an onEdit trigger. Google does not allow such a thing to happen.

Google不想告诉我们复杂标准"是什么,所以我们不知道.据我了解,简单的触发器onEdit不应访问任何人的个人信息,即使您也是如此.一个可安装的触发器(您通过资源"菜单创建的触发器)可以访问您的个人信息,但不能访问其他人的信息.您可能将两者混为一谈.

Google didn't want to tell us what the "complex criteria" are, so we don't know. To my understanding, a simple trigger onEdit should not have access to anyone's personal information, even yours. An installable trigger (one that you create through Resources menu) has access to your personal information, but not of others. It's possible you mixed up both of those.

在电子表格的不同标签之间移动数据

moving data between different tabs of a spreadsheet

使用getSheetByName()获取所需工作表上的手柄,在其中选择一个范围,然后使用source.copyTo(target)复制数据.

Use getSheetByName() to get a handle on the sheet you want, select a range there, and use source.copyTo(target) to copy data.

跨独立电子表格(具有不同的电子表格ID)

across independent spreadsheets (with different spreadsheet Ids)

在源电子表格中使用range.getValues(),在目标电子表格中使用target.setValues().您需要SpreadsheetApp.openById来处理后者.

Use range.getValues() in the source spreadsheet and target.setValues() in the target spreadsheet. You'll need SpreadsheetApp.openById to get a handle on the latter.

这篇关于为什么我的Google电子表格脚本无法在getUser()上捕获电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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