Integrations

Google Sheets and Drive

Connecting

Both subsystems authenticate through GPAL.Credentials using a Google service account and the relevant OAuthScope (Google_Sheets or Google_Drive). See Credential Management in Core Concepts for how WithServiceAccountKey and WithScope fit together. GPAL.GoogleSheets.WithSpreadsheet(idOrTitle) selects the spreadsheet, then WithSheet(nameOrIndex) selects a worksheet within it. GPAL.GoogleDrive.WithCredentials(credentials) connects to Drive directly; WithLocalFile and WithFileId then target the local and remote sides of a file operation.

var credentials = GPAL.CredentialsFor(CredentialServiceType.Google)

.WithServiceAccountKey(GPAL.FileFor("service-account.json"))

.WithScope(OAuthScope.Google_Sheets)

.ToGPALObject();


var sheet = GPAL.GoogleSheets

.WithSpreadsheet("Quarterly Report")

.WithSheet("Summary");

Reading and Writing Data

On a selected sheet, WithReadRange sets an A1-notation range and SaveTo(out grid) or SaveTo(file) exports it. The same shapes GPAL.Excel uses for local workbooks. WithData supplies a grid to write, WithWriteRange sets the destination range, and WriteToSheet or AppendToSheet perform the write. On Drive, UploadTo and SaveTo move a file between local disk (WithLocalFile) and Drive (WithFileId), while MoveTo, RenameTo, DeleteFile, and ListFiles manage files already there.

// Read a range into a grid, then write a different range back

IGPALGrid<string> data;

sheet.WithReadRange("A1:D50").SaveTo(out data);


sheet.WithData(summaryGrid)

.WithWriteRange("F1")

.WriteToSheet();


// Upload a local export to Drive

GPAL.GoogleDrive

.WithCredentials(credentials)

.WithLocalFile("export.csv")

.UploadTo("export.csv");

Managing Sheets, Formatting, and Apps Script

Beyond reading and writing data, GPAL.GoogleSheets can create, rename, or delete worksheets and rename the spreadsheet itself. Cell formatting is available through a fluent range-then-format chain covering alignment, color, and number format. Apps Script support lets you push a script file to the spreadsheet's project and publish it as a callable web app -- the same things you can do from the Google Sheets toolbar, expressed as workflow steps.

💬 Ask GPAL