I'm building an add-on. I've noticed I can have multiple html files. Can I also have multiple code files, that is, more than just Code.gs?
If so, how to I cause them to be loaded? If not, how does Sheets know whether a function defined in Code.gs can be used in a formula or not?
LATER
So it has been suggested, seeing that the script editor allows you to create extra gs files, that simply having the custom function in another script file within the add-on is sufficient. However, I'm not having a lot of success with that.
So apart from my Code.gs, I have Medical.gs with the following in it:
/**
* Gargling function for digital sore throat
*
* @param {object} input The thing to gargle
* @return the gargled parameter
* @customfunction
*/
function GARGLE(input) {
console.log("GARGLE");
return "GARGLE";
}
Even with the JSDoc header, the custom function is invisible when, from the Run menu in the Script Editor, I select the "Test as add-on" and run the prepared test spreadsheet. In the spreadsheet I can do =GARGLE()
as much as I like, but I still get the standard #NAME?
error.
LATER STILL
So I put a similar custom function into a fresh standalone script project's Code.gs. When tested as an add-on the target spreadsheet can't even see this one. Going slightly nuts here.