如何将具有触发器和功能的脚本连接到多个Google表格? [英] How to Connect a Script with Triggers and Functions to Multiple Google Sheets?

查看:71
本文介绍了如何将具有触发器和功能的脚本连接到多个Google表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下代码的独立脚本:

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
}

这包括3个部分-脚本连接到的Google电子表格的键,电子表格的触发器创建功能和该功能.

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.

我需要将此脚本连接到多张纸.到目前为止,我正在为每个工作表创建单独的独立脚本.

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?

推荐答案

由于存在限制创建触发器

如果脚本是从该文档创建的,而不是作为独立脚本,则该脚本将绑定到Google表格,文档或表格文件.

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.

您可以使用doGetdoPost函数将脚本另存为独立服务.并在触发器上通过自己的脚本向电子表格发出请求.

You could save your script as standalone service with doGet or doPost function. And make requests to it from your spreadsheets by their own scripts on trigger.

这篇关于如何将具有触发器和功能的脚本连接到多个Google表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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