bugmagnet
bugmagnet

Reputation: 7769

In a standalone google-apps-script project, where would the spreadsheet functions be stored?

Where the Code.gs file is bound to the spreadsheet, user-defined functions are stored there along with any other functions like event handlers.

In a standalone project, would Code.gs hold user-defined functions or is there some other mechanism which makes functions defined in a standalone project visible to the spreadsheet that uses it?

Upvotes: 0

Views: 80

Answers (1)

Tanaike
Tanaike

Reputation: 201378

  • You want to use a function in the standalone script as a custom function.

If my understanding is correct, unfortunately, the function in the standalone script cannot be directly used as the custom function for Spreadsheet. So as a workaround, how about using the standalone script as a library? Please think of this as just one of several answers.

Sample situation:

The sample situation is as follows.

  • Standalone script has a function of myFunction(). This is used as a library. The sample library name is "SampleLib". The sample script is as follows.

    function myFunction(e) {
      return "Done: " + e;
    }
    
  • Container-bound script of Spreadsheet has a function of CustomFunction(). The sample script is as follows. Before you use this script, please install above library.

    function CustomFunction(e) {
      return SampleLib.myFunction(e);
    }
    
    • After the library is installed in the bound script, when =CustomFunction("sample") is put in a cell, Done: sample is returned. By this, it is found that myFunction() of the library of "SampleLib" is used.

Note:

  • As another workaround, I think that Web Apps can be also used. But the process cost will be higher than that of the library.

Reference:

If this workaround was not the result you want, I apologize.

Upvotes: 1

Related Questions