GoogleSheets

Google Apps Script Integration

UploadScript uploads a .gs script file or a raw script string to the spreadsheet's Apps Script project. GetOrCreateScriptProject creates a new Apps Script project linked to the spreadsheet, or retrieves the existing one. SetupCloudProject links an existing Google Cloud project by name. DeployScriptAsWebApp deploys the uploaded script as a web app and returns the URL. CreateTrigger adds a time-driven or event-driven trigger to the script. Configure deployment with WithDeploymentDescription, WithExecuteAs, WithScriptAccess, WithVersionNumber, and WithScriptName.

WARNING

UploadScript has both a GPALFile overload (reads the script from a .gs file on disk) and a separate string overload (uploads the string directly as the script source). As with Converter.WithInput, C# resolves a bare string argument to the string overload, so UploadScript("automation.gs") would upload the literal text 'automation.gs' as the script, not the file's contents. Use GPAL.FileFor("automation.gs") to upload from a file.

Examples

GPAL Fluent: High-level fluent C# API

//DeployScriptAsWebApp returns the deployment URL as an out string. Scripts must have a doGet or doPost function to be usable as a web app. Triggers can be TimeBased or event-based (Edit, Open, FormSubmit, Change and the rest).

// the Sheets object first, then the credentials that drive the API

GoogleSheets sheets = (GoogleSheets)GPAL.GoogleSheets.ToGPALObject();

sheets.WithCredentials(googleCreds);


// Upload and deploy a script

string webAppUrl;

sheets.WithSpreadsheet("spreadsheet-id");


sheets

.WithProjectId("gcp-project-id")

.WithScriptName("MyAutomation")

.WithExecuteAs(ExecuteAsType.USER_DEPLOYING)

.WithScriptAccess(ScriptAccessType.ANYONE)

.WithDeploymentDescription("v1.0 initial deploy")

.UploadScript((GPALFile)"automation.gs")

.DeployScriptAsWebApp(out webAppUrl);


// Add a time-driven trigger

sheets.WithSpreadsheet("spreadsheet-id");


sheets

.WithSheet("Report")

.WithTriggerFunction("runDailyReport")

.WithTriggerSchedule(TriggerScheduleType.Daily)

.CreateTrigger(GoogleTriggerType.TimeBased);

💬 Ask GPAL