如何为程序创建的Google表单/表单编写绑定脚本 [英] How to write a bound script for a programmatically created google form/sheet

查看:112
本文介绍了如何为程序创建的Google表单/表单编写绑定脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google表单,以编程方式为事件创建注册表单(以及关联的电子表格)。这些表单将收集电子邮件,并且我希望向使用这些以编程方式创建的表单的注册人发送通知电子邮件 - 而无需手动进入这些表单/电子表格中的每一个,以插入可实现该功能的脚本。换句话说,是否有一种方法为程序创建的Google表单/表单创建绑定脚本?

解决方案

Apps脚本包含特殊的API,可让您以编程方式创建,阅读和编​​辑Google表格。 Apps脚本可以通过两种广泛的方式与Google表格进行交互:如果脚本的用户对电子表格具有适当的权限,则任何脚本都可以创建或修改电子表格,并且还可以将脚本绑定到电子表格,从而使脚本具有特殊的能力用户界面或在电子表格打开时作出响应。要创建绑定脚本,请从Google表格中选择工具>脚本编辑器。



绑定到Google表格文件的脚本可以使用简单的触发器,如onOpen和onEdit()可在编辑权限的用户打开或编辑电子表格时自动响应。

为了让它以编程方式进行,我认为你可以使用可安装的触发器。它让Google表格在发生某些事件(例如打开文档)时自动运行一个功能。然而,可安装的触发器比简单的触发器提供了更大的灵活性,它们可以调用需要授权的服务,并提供多种其他类型的事件,包括时间驱动(时钟)触发器,它们也可以通过程序控制。对于简单的和可安装的触发器,Apps脚本都会将触发函数传递给一个事件对象,该事件对象包含有关事件发生的上下文信息。 检查此 page 了解更多关于可安装触发器的信息。



Apps脚本还包含特殊的API,可让您以编程方式创建,阅读和编​​辑Google Apps文件。要构建大部分附加组件,您至少需要熟悉其中一个服务。




  • 电子表格服务

  • 文件服务

  • 表单服务



注意:只有拥有编辑电子表格,文档或表单权限的用户才能运行绑定脚本。只有查看权限的协作者无法打开脚本编辑器,但是如果他们创建了父文件的副本,他们将成为副本的所有者,并且将能够查看并运行该脚本的副本。


I have a google form that programmatically creates registration forms (with associated spreadsheet) for events. These Forms will collect emails and I'd like to send a notification email to registrants who use these programmatically created forms - without having to go manually into each one of these forms/spreadsheets to insert the script that would achieve that. In other words is there a way of creating a bound script for a programmatically created google form/sheet?

解决方案

Apps Script includes special APIs to let you programmatically create, read, and edit Google Sheets. Apps Script can interact with Google Sheets in two broad ways: any script can create or modify a spreadsheet if the script's user has appropriate permissions for the spreadsheet, and a script can also be bound to a spreadsheet, which gives the script special abilities to alter the user interface or respond when the spreadsheet is opened. To create a bound script, select Tools > Script editor from within Google Sheets.

Scripts that are bound to a Google Sheets file can use simple triggers like the functions onOpen() and onEdit() to respond automatically when a user who has edit access to the spreadsheet opens or edits the spreadsheet.

To make it programmatically i think you can use the installable trigger. It let Google Sheets run a function automatically when a certain event occurs, such as opening a document. Installable triggers, however, offer more flexibility than simple triggers they can call services that require authorization and offer several additional types of events including time-driven (clock) triggers,they can also be controlled programmatically. For both simple and installable triggers, Apps Script passes the triggered function an event object that contains information about the context in which the event occurred.

Check this page for more information about installable triggers

Also Apps Script includes special APIs to let you programmatically create, read, and edit Google Apps files. To build most add-ons, you'll need to be familiar with at least one of these services.

  • Spreedsheet Service
  • Document Service
  • Forms Service

NOTE: Only users who have permission to edit a spreadsheet, document, or form can run its bound script. Collaborators who have only view access cannot open the script editor, although if they make a copy of the parent file, they become the owner of the copy and will be able to see and run a copy of the script.

这篇关于如何为程序创建的Google表单/表单编写绑定脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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