google-sheetsgoogle-apps-script

How can I use a Custom Function in Formulas across Multiple Spreadsheets?


Is there a way I can use a custom function in formulas on sheets across multiple spreadsheets?

I know you can create an appsscript function on a spreadsheet and use it in a sheet formula, but I want to use the function across multiple spreadsheets.

The spreadsheets I want to use the function in are automatically generated so the solution needs to be something that can be done programmatically.

I thought one solution might be to add the function to the Google Workspace Marketplace and install it, but it looks like there is no way to programmatically install an add on.

The reason I want the function as a formula on the sheet, is because the value depends on the value that is entered in another cell on the sheet and I want it to be able to change with this value.

I also thought about using an onEdit trigger but it seems like you can't create event triggers for external spreadsheets.

The function uses LinearOptimization so I am fairly certain it can't be done using basic formula functions.

Any help is much appreciated! Thank you!


Solution

  • My solution is to use a template sheet that has the appscript function, and to make a copy of it when generating my new spreadsheets. The appscript function will be copied over too so I can use it in the formulas!