当一个电子表格被另一个激活时,是否可以提示显示? [英] Is it Possible to Have a Prompt Show up For One Spreadsheet When Activated by Another?

查看:30
本文介绍了当一个电子表格被另一个激活时,是否可以提示显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用一个脚本来创建同时适用于 2 个电子表格(2 个独立文件)的触发器?我被困在如何做这部分,因为它需要自动化.到目前为止,在我的研究中,我看到了 importrange 触发器,但没有任何东西可以在特定工作表上进行提示.

Is it possible to have triggers that work for 2 spreadsheets (2, independent files) with one script? I am stuck at how to do this part, as it needs to be automated. So far in my research I have seen importrange triggers but nothing that can do a prompt on a specific worksheet.

我的目标是进行列表否决"具有以下要求的功能:

My goal is to make a "list veto" function with the following requirements:

  1. 必须使用谷歌电子表格a) 一张带有触发器"的表;那就是控制器"或版主b) 首选"一张纸选民c) 次要"一张纸选民

  1. Must use google spreadsheets a) One Sheet with "triggers" that is the "controller" or moderator b) One Sheet for the "preferred" elector c) One Sheet for the "secondary" elector

该列表将是动态的,但在本示例中,我们假设它包含 15 个位置的列表.

The list will be dynamic, but for this example let us say it consists of a list of 15 locations.

两个选举人"将不得不连续否决,直到只剩下 8 个位置为止.

Both "electors" will have to veto continuously until there is only 8 locations left.

控制器"将触发询问首选选民"的系统首先,然后是次要",通过进入各自电子表格的提示.一旦首选做出选择,位置列表将被扣除,然后提示转到次要"的工作表.

The "controller" will trigger a system that asks the "preferred elector" first, then the "secondary," by a prompt that goes to their respective spreadsheet. Once the preferred makes a choice, the list of locations is deducted, then a prompt goes to the worksheet of the "secondary."

推荐答案

触发器由电子表格设置,而不是由工作表设置,但您可以使用 JavaScript 控制语句,如 if..else切换以控制何时应执行脚本的某些部分.

Triggers are set by spreadsheet, not by sheet, but you could use JavaScript control statements like if..else and switch to control when should be executed parts of your script.

示例:

function respondToOnEdit(e){
  var sheetName = e.source.getActiveSheet().getName();
  if(sheetName === 'Sheet1'){
    // do something when Sheet1 is edited
  } else if(sheetName === 'Sheet2'){
    // do something when Sheet2 is edited  
  } else {
    // do something when any other sheet is edited
  }
}

您必须使用代码为每个电子表格创建一个可安装的触发器.

You will have to use code to create an installable trigger for each spreadsheet.

代码片段:

[id1, id2].forEach(id => {
var spreadsheet = SpreadsheetApp.openById(id);
ScriptApp.newTrigger('respondToOnEdit')
.forSpreadsheet(spreadsheet)
.create()
}

相关

这篇关于当一个电子表格被另一个激活时,是否可以提示显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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