\n
Example Standalone Script:
\n\nExample Result of the Workaround:
\n\nYou can now use the custom function in the Google Sheets
\n\n","author":{"@type":"Person","name":"Kristkun"},"upvoteCount":3}}}Reputation: 48
For example, I'd like to write a (Python, say) program that generates a Google sheet, then writes some custom .gs code into the Apps Script attached to that sheet, then writes values into the sheet itself using formulas defined in the Apps Script. What I currently do is use Tools > Script Editor, then manually copy-paste the relevant Apps Script code.
Upvotes: 1
Views: 277
Reputation: 5963
As mentioned by @Tanaike, You can use Apps Script API to add container-bound script.
What to do:
To set a container-bound script, you need to assign the spreadsheet file id to the parentId parameter
Sample Request Body:
{
"title": "new",
"parentId": "spreadsheet file id"
}
Sample Response Body:
{
"scriptId": "newly created script id",
"title": "new",
"parentId": "spreadsheet file id",
"createTime": "2020-12-25T23:33:48.026Z",
"updateTime": "2020-12-25T23:33:48.026Z"
}
Sample Request Body:
{
files: [{
name: 'hello',
type: 'SERVER_JS',
source: 'function helloWorld() {\n console.log("Hello, world!");\n}'
}, {
name: 'appsscript',
type: 'JSON',
source: "{\"timeZone\":\"America/New_York\",\"" +
"exceptionLogging\":\"CLOUD\"}"
}]
}
scriptId can be seen in your standalone script project under File -> Project Properties
To set a container-bound script, you need to assign the spreadsheet file id to the parentId parameter
Sample Request Body:
{
"title": "new",
"parentId": "spreadsheet file id"
}
Sample Response Body:
{
"scriptId": "newly created script id",
"title": "new",
"parentId": "spreadsheet file id",
"createTime": "2020-12-25T23:33:48.026Z",
"updateTime": "2020-12-25T23:33:48.026Z"
}
Use the content resource returned in Step 2 as the request body. Make sure to replace the script id based on the newly created bound script id that is obtained in Step 4.
Example Standalone Script:
Example Result of the Workaround:
You can now use the custom function in the Google Sheets
Upvotes: 3