Is there a way to set an App Script on a new Google Sheet via the Google Sheets API? We use pygsheets as our Python API Client for Google Sheets. Since we are using the onSelectionChange
trigger to populate certain cells with a date, we would like to setup the app script after we have populated rows in the spreadsheet.
The Google Sheets API doesn't have a method to do this. You can use the Apps Script API instead, but there are a few caveats which may or may not work with your use case:
projects.create
to create a new Apps Script project and attach it to a Sheets file by specifying the parentId
field, which is the Sheet's ID. However, there are no methods to attach a preexisting script to a Sheet. You can still use projects.updateContent
to add the required script files, though.