简体   繁体   English

如何将具有触发器和功能的脚本连接到多个Google表格?

[英]How to Connect a Script with Triggers and Functions to Multiple Google Sheets?

I have a standalone script with the following code: 我有一个带有以下代码的独立脚本:

var key = "ID of the Sheet";

function createTriggers() {

  ScriptApp.newTrigger('filter')
      .forSpreadsheet(key)
      .onEdit()
      .create();
}

function filter(){
var ss = SpreadsheetApp.openById(key);
// rest of the function below
}

This has 3 parts - The key of the Google spreadsheet the script is connected to, the trigger creation function of the spreadsheet and the function. 这包括3部分-脚本连接到的Google电子表格的键,电子表格的触发器创建功能和功能。

I need this script to be connected to multiple sheets. 我需要将此脚本连接到多张纸。 As of now, I am creating individual standalone script for each sheet. 到目前为止,我正在为每个工作表创建单独的独立脚本。

How to have multiple sheets connected to the same standalone script when the code is in the above format? 当代码采用上述格式时,如何将多个工作表连接到同一独立脚本?

If we cannot have multiple sheets connected to this script, is there any other way that's better than creating a standalone scripts for each and every sheet? 如果我们不能将多个工作表连接到该脚本,那么还有什么其他方法比为每个工作表创建独立脚本更好吗?

Since there is a restriction for creating triggers 由于存在创建触发器的限制

A script is bound to a Google Sheets, Docs, or Forms file if it was created from that document rather than as a standalone script. 如果脚本是从该文档创建的,则该脚本将绑定到Google表格,文档或表格文件,而不是作为独立脚本。

You could save your script as standalone service with doGet or doPost function. 您可以使用doGetdoPost函数将脚本另存为独立服务。 And make requests to it from your spreadsheets by their own scripts on trigger. 并在触发时通过自己的脚本从电子表格中发出请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM