1
votes

I have some Google Apps Script functions which are to be made available to many spreadsheets. Perfect candidate scenario for a library object. I can write a stand alone script and include this as library resource for other spreadsheets. I can also create a Spreadsheet with attached script and similarly use the script object as other spreadsheets' library resource. If I keep the library script bound to a spreadsheet I have a more rich development environment (my code has an activespreadsheet object at runtime) than if I maintained a stand alone script, bound to no spreadsheet object.

My question is - are there any disadvantages to maintaining library functions in a script attached to a spreadsheet, rather than maintaining a stand-alone script?

1

1 Answers

1
votes

Not really. Bound scripts can call a few methods that standalone scripts cannot like the ones mentioned in Special methods.

  • getActiveSpreadsheet(), getActiveDocument(), and getActiveForm() allow bound scripts to refer to their parent file without referring to the file's ID.
  • getUi lets bound scripts access the user interface for their parent file to add custom menus, dialogs, and sidebars.
  • In Google Sheets, getActiveSheet(), getActiveRange(), and getActiveCell() let the script determine the user's current sheet, selected range of cells, or selected individual cell. setActiveSheet(sheet) and setActiveRange(range) let the script change those selections.
  • In Google Docs, getCursor() and getSelection() let the script determine the position of the user's cursor or selected text. setCursor(position) and setSelection(range) let the script change those locations.

You can check info about Standalone scripts in the official doc.