GoogleSheets

Connection and Sheet Selection

WithCredentials supplies the Google API credentials - build them with GPAL.Credentials using a service account key and the GoogleSheets OAuth scope. WithSpreadsheet selects the target spreadsheet by its ID or title. WithSheet selects the target worksheet within the spreadsheet by name, or by the sheet's own id, which is the gid in the spreadsheet URL. ToGPALObject returns the IGoogleSheets interface for storage or injection. WithWebAppUrl names the Apps Script web app to drive the spreadsheet through, instead of the Sheets API.

Examples

GPAL Fluent: High-level fluent C# API

//WithSpreadsheet accepts either the spreadsheet ID (from the URL) or the spreadsheet title. WithSheet accepts a sheet name, or the sheet's id as an integer. The id is the gid Google assigns, the number after gid= in the spreadsheet URL, and it is not a position: the first sheet of a new spreadsheet has gid 0, but the second is whatever Google gave it. Name the sheet when you know its name.

// Connect to a spreadsheet

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

sheets.WithCredentials((Credentials)GPAL.CredentialsFor(CredentialServiceType.Google)

.WithUsername("you@example.com")

.WithPassword("your-password")

.WithServiceAccountKey((GPALFile)"service-account.json")

.WithScope(OAuthScope.Google_Sheets));


sheets

.WithSpreadsheet("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms")

.WithSheet("Sheet1");


// or by the sheet's own id, the gid from the URL

sheets

.WithSpreadsheet("1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms")

.WithSheet(0);


// List all sheets in a spreadsheet

sheets

.WithSpreadsheet("spreadsheet-id")

.ListSheets(out var sheetList);

💬 Ask GPAL