2
votes

I have functions defined in a script project that belongs to a spreadsheet, and would like to use them in other spreadsheets as well. These are functions designed to be called from a cell in the spreadsheet.

I can save a version of the project, and import it as a library into the other, but this does not allow the functions to be called directly from the spreadsheet. (As far as I can tell).

The same problem applies if I create a stand-alone script project in Drive, and import it as a library into both spreadsheets.

Where should I put functions that I want to be able to call directly from multiple spreadsheets? If they go in a library, how do I call them directly from the spreadsheet?

Thanks!

1
Possible duplicate of Use script in all spreadsheetsRubén
Now you could use add-ons. See the answer by Mogsdad on the above linked question.Rubén

1 Answers

4
votes

To call functions from within a spreadsheet, all those functions need to be defined within the spreadsheet's scripts.

What you can do is Write a library and in each spreadsheet you want this code to be available, make available shell functions which in turn call the actual functions from the library.

So, in your spreadsheet's script editor, write a function such as

function customFunc(arg1, arg2){ 
   return Library.customFunc(arg1, arg2); 
}

You can have the customFunc in a library which does the hard work.