简体   繁体   English

Google Scripts API:如何将onEdit函数应用于每个电子表格?

[英]Google Scripts API: How to apply an onEdit function to every spreadsheet?

I wrote a little function that creates some menus and registered it with the onOpen() event with my spreadsheet in Google Drive so that the actions are triggered and the menus appear automatically whenever the particular spreadsheet gets opened. 我写了一个小函数,创建了一些菜单,并使用我在Google云端硬盘中的电子表格的onOpen()事件进行了注册,以便触发操作,并在特定电子表格打开时自动显示菜单。 But there's a catch. 但是有一个问题。 I want this to happen for every single spreadsheet that I will ever have in Google Drive/Docs. 我希望这会发生在Google Drive / Docs中我将拥有的每个电子表格中。 Even the ones I create next week. 甚至是我下周创建的那些。 Of course, I don't want to go through the process of registering a trigger for each particular document. 当然,我不想经历为每个特定文档注册触发器的过程。

Is there a way to say "hey, every single spreadsheet in my account will have this function triggered on onOpen"? 有没有办法说“嘿,我帐户中的每个电子表格都会在onOpen上触发此功能”? It seems like a highly usefull feature. 这似乎是一个非常有用的功能。

If this is not possible, can Zend's GData API for PHP somehow remotely run a script on a spreadsheet? 如果这是不可能的,Zend的PHP GData API能否以某种方式在电子表格上远程运行脚本? Since all my spreadsheets come from a PHP web app, I could overcome the problem by triggering the execution from PHP. 由于我的所有电子表格都来自PHP Web应用程序,因此我可以通过触发PHP执行来解决问题。

If you're willing to change the way you create a new spreadsheet, rather than "Create New", then you should be able to acheive this with all your future spreadsheets. 如果您愿意更改创建新电子表格的方式,而不是“新建”,那么您应该可以使用所有未来的电子表格来实现这一点。

  • Create a blank spreadsheet with your onOpen() code. 使用onOpen()代码创建一个空白电子表格。 Save it. 保存。

  • To make a new spreadsheet that has your menu, select your "template" spreadsheet, use More - Make a Copy , and then rename the copy. 要制作包含菜单的新电子表格,请选择“模板”电子表格,使用More - Make a Copy ,然后重命名副本。

When you copy a spreadsheet, any included script is also copied. 复制电子表格时,也会复制任何包含的脚本。 (Unfortunately, it gets named "Copy of...", but that doesn't affect functionality.) (不幸的是,它被命名为“Copy of ...”,但这不会影响功能。)

Alternative: You can also use a Script Library with functions that you would like to change in future, and have the template script call them. 替代方案:您还可以使用脚本库以及将来要更改的函数,并让模板脚本调用它们。 (Libraries added via the "Manage Libraries..." dialog will be included in the copy.) (通过“管理库...”对话框添加的库将包含在副本中。)

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

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