简体   繁体   中英

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. But there's a catch. I want this to happen for every single spreadsheet that I will ever have in 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"? 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? Since all my spreadsheets come from a PHP web app, I could overcome the problem by triggering the execution from 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. 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.

When you copy a spreadsheet, any included script is also copied. (Unfortunately, it gets named "Copy of...", but that doesn't affect functionality.)

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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