弹出仅显示给文档所有者 [英] Pop up to only show for the doc owner

查看:78
本文介绍了弹出仅显示给文档所有者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本,用于在打开文档时简单弹出.有什么办法可以使此弹出窗口仅显示给工作表所有者,而不是与文档共享的所有其他人?

I have the following script for a simple pop up on opening the doc. Is there any way for this pop up to only show to the sheet owner and not all the other people the doc is shared with?

function onOpen() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var ui = SpreadsheetApp.getUi();
var Alert = ui.alert("TEXT HERE");
}

我的用例是,只有作为文档所有者的我才能看到此消息,我不希望其他拥有共享权限的人(例如客户)看到.

My use case for this, is a message visible to only me as the doc owner, which I don't want anybody else with sharing rights, ie clients, to see.

推荐答案

  • 您只想在所有者打开电子表格时打开对话框.
  • 不是所有者的共享用户打开电子表格时,您不想打开对话框.
  • 如果我的理解是正确的,那么该修改如何?

    If my understanding is correct, how about this modification?

    在此修改中,它知道所有者是否通过检索活动用户的电子邮件来打开电子表格.

    In this modification, it knows whether owner opened the Spreadsheet by retrieving the email of active user.

    • 所有者打开电子表格时,Session.getActiveUser().getEmail()的值是所有者的电子邮件.
    • 不是所有者的用户打开电子表格时,不会检索到Session.getActiveUser().getEmail()的值.
    • When owner opens the Spreadsheet, the value of Session.getActiveUser().getEmail() is owner's email.
    • When users, who are not owner, open the Spreadsheet, no value of Session.getActiveUser().getEmail() is retrieved.

    使用.

    function onOpen() {
      var email = Session.getActiveUser().getEmail();
      if (email) {
        var ss = SpreadsheetApp.getActiveSpreadsheet();
        var ui = SpreadsheetApp.getUi();
        var Alert = ui.alert("TEXT HERE");
      }
    }
    

    注意:

    • 对于您的脚本,不需要安装该功能作为OnOpen的可安装触发器.
    • 即使已安装OnOpen的可安装触发器,当用户打开电子表格时,也不会检索到Session.getActiveUser().getEmail()的值.所以我认为可以使用.当时Session.getActiveUser().getEmail()拥有所有者的电子邮件.
    • Note:

      • In the case of your script, it is not required to install the function as the installable trigger of OnOpen.
      • Even if the installable trigger of OnOpen is installed, when users open the Spreadsheet, no value of Session.getActiveUser().getEmail() is retrieved. So I think that this can be used. At that time, Session.getActiveUser().getEmail() has owner's email.
      • 如果我误解了您的问题,而这不是您想要的结果,我深表歉意.

        If I misunderstood your question and this was not the result you want, I apologize.

        如果所有用户都安装了触发器,则Session.getEffectiveUser().getEmail()返回该值.因此,需要将该值与注册用户的值进行比较.在此示例脚本中,假设如下.

        If all users install the trigger, Session.getEffectiveUser().getEmail() returns the value. So the value is required to be compared with that of the registered users. In this sample script, it supposes as follows.

        • "email1"和"email2"的用户由每个用户安装OnOpen的可安装触发器.
        • Users of "email1" and "email2" install the installable trigger of OnOpen by each user.
        var users = ["email1", "email2",,,]; // Please set emails of users who can open the dialog.
        var email = Session.getEffectiveUser().getEmail();
        if (users.indexOf(email) > -1) {
          var ss = SpreadsheetApp.getActiveSpreadsheet();
          var ui = SpreadsheetApp.getUi();
          var Alert = ui.alert("TEXT HERE");
        }
        

        当我刚刚由3个用户测试这种情况时,我注意到了新问题.

        Edit 2:

        When I tested this situation by 3 users just now, I noticed new issue.

        首先,它假定如下.

        • 电子表格由拥有者user1和user2的3个用户共享和使用.
        • 打开电子表格时,功能会运行onOpen_sample(){}.
        • 所有者和user1可以运行脚本并打开对话框ui.alert("TEXT HERE").
        • Spreadsheet is shared and used by 3 users who are owner, user1 and user2.
        • Function is run onOpen_sample(){} when the Spreadsheet is opened.
        • When owner and user1 can run the script and open a dialog ui.alert("TEXT HERE").

        在这种情况下,可获得以下结果.

        In this situation, the following results are obtained.

        1. 所有者安装了onOpen_sample()作为OnOpen的触发器.
          • Session.getActiveUser().getEmail()返回所有者的电子邮件.
          • Session.getEffectiveUser().getEmail()返回所有者的电子邮件.
        1. Owner installed onOpen_sample() as a trigger of OnOpen.
          • Session.getActiveUser().getEmail() returns owner's email.
          • Session.getEffectiveUser().getEmail() returns owner's email.
        • Session.getActiveUser().getEmail()不返回任何值.
        • Session.getEffectiveUser().getEmail()返回用户1的电子邮件.
        • Session.getActiveUser().getEmail() returns no value.
        • Session.getEffectiveUser().getEmail() returns user1's email.

        在这里

        1. User2不会安装onOpen_sample()作为OnOpen的触发器.
          • Session.getActiveUser().getEmail()不返回任何值.
          • Session.getEffectiveUser().getEmail()返回user1的电子邮件.
            • 这不是所有者的电子邮件.
        1. User2 doesn't install onOpen_sample() as a trigger of OnOpen.
          • Session.getActiveUser().getEmail() returns no value.
          • Session.getEffectiveUser().getEmail() returns user1's email.
            • This is not owner's email.

        此外,

        1. 用户2已安装onOpen_sample()作为OnOpen的触发器.
          • Session.getActiveUser().getEmail()不返回任何值.
          • Session.getEffectiveUser().getEmail()返回所有者的电子邮件.
            • 这不是用户2的电子邮件.
        1. User2 installed onOpen_sample() as a trigger of OnOpen.
          • Session.getActiveUser().getEmail() returns no value.
          • Session.getEffectiveUser().getEmail() returns owner's email.
            • This is not user2's email.

        而且,当我多次安装OnOpen触发器时,即使user1和user2安装了触发器,Session.getEffectiveUser().getEmail()也只返回所有者的电子邮件.

        And also, when I installed the trigger of OnOpen several times, even if user1 and user2 install the trigger, Session.getEffectiveUser().getEmail() got to return only owner's email.

        通过这些,所有用户都可以运行脚本并打开对话框.我以为您的问题可能就是这个.我认为这可能是一个错误.因此,我想将此报告给问题跟踪器.

        By these, all users can run the script and open the dialog. I thought that your issue might be this. I think that this might be a bug. So I would like to report this to the issue tracker.

        从这种情况下,在当前阶段,发现以下结果.

        From this situation, in the current stage, it was found the following result.

        1. 只有所有者可以运行脚本并打开对话框.
        2. 特定用户无法运行脚本并打开对话框.

        很抱歉您的问题尚未解决.如果找到解决方法,我想在这里报告.

        I apologize that your issue was not resolved. If I found the workaround, I would like to report here.

        这篇关于弹出仅显示给文档所有者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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