How to make set of scripts available for all my Go

2020-02-29 18:38发布

问题:

Excel supports the concept of a PERSONAL.XLS file which contains my personal scripts, which I want to be able to use on any spreadsheet/workbook that I open.

How do I do similar in Google Docs, i.e. have a set of scripts which, regardless of which Google Spreadsheet I open, will cause the onOpen event to be run and will thus add my extra menu?

回答1:

You cannot do that in Google Spreadsheets. However the best practice is to

  1. Write a standalone script with your onOpen and other functions.
  2. Publish this as a library
  3. Write a shell onOpen in each of the spreadsheets that you create manually. :( This shell function will call the library's onOpen.

However, if you create a copy of a spreadsheet that has an associated script, then the copy will also have the script in it.



回答2:

1) You can open your Script and from the Publish menu select "Test as add-on".

2) Now under "Configure New Test" you can select a document and then run the add-on for that doc.

Unfortunately you have to do this for each document one at a time. I would really love it if there was a way to tell a script to be available for all my spreadsheets, or at least have an easy way to install a personal add-on on a per-sheet basis just like you can install an add-on from the marketplace, kinda like a personal marketplace.



回答3:

Although not recommended, You can also copy set of scripts to all other google spreadsheets programmatically using AppsScriptApi