GoogleSheets

Google Apps Script Integration

Methods for uploading, deploying, and triggering Google Apps Script within a spreadsheet.

Methods for uploading, deploying, and triggering Google Apps Script within a spreadsheet.

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 TimeDriven or event-based (OnEdit, OnOpen, etc.).

// Upload and deploy a script string webAppUrl; GPAL.GoogleSheets .WithCredentials(googleCreds) .WithSpreadsheet("spreadsheet-id") .WithProjectId("gcp-project-id") .WithScriptName("MyAutomation") .UploadScript(GPAL.FileFor("automation.gs")) .WithDeploymentDescription("v1.0 initial deploy") .WithExecuteAs(ExecuteAsType.User) .WithScriptAccess(ScriptAccessType.Anyone) .DeployScriptAsWebApp(out webAppUrl); // Add a time-driven trigger GPAL.GoogleSheets .WithCredentials(googleCreds) .WithSpreadsheet("spreadsheet-id") .CreateTrigger(GoogleTriggerType.TimeDriven) .WithTriggerFunction("runDailyReport") .WithTriggerSchedule(TriggerScheduleType.Daily);