GoogleSheets

Reading and Writing Data

WithReadRange sets the A1-notation range to read. SaveTo(out IGPALGrid<string>) exports the range to an in-memory grid. SaveTo(GPALFile) exports to a file. WithData sets the grid to write. WithWriteRange sets the destination range for writes. WriteToSheet writes the grid to the specified sheet. AppendToSheet appends the grid as new rows at the end. InsertAtCell, AppendToCell, and PrependToCell write a single value to a specific cell position.

Examples

GPAL Fluent: High-level fluent C# API

//WithWriteRange sets the top-left cell for write operations - GPAL expands the range to fit the grid dimensions. AppendToSheet always adds rows at the bottom of existing data.

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

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

sheets.WithCredentials(googleCreds);


// Read a range into a grid

sheets

.WithSpreadsheet("spreadsheet-id")

.WithSheet("Data")

.WithReadRange("A1:D100")

.SaveTo(out var grid);


// Write a grid to a sheet

sheets

.WithSpreadsheet("spreadsheet-id")

.WithSheet("Results")

.WithData(myGrid)

.WithWriteRange("A1")

.WriteToSheet("Results");


// Append rows to a sheet

sheets

.WithSpreadsheet("spreadsheet-id")

.WithSheet("Results")

.WithData(newRowsGrid)

.AppendToSheet("Log");

💬 Ask GPAL