Class GoogleSpreadsheetsDataProvider
- Namespace
- combit.Reporting.DataProviders
- Assembly
- combit.ListLabel31.CrossPlatform.dll
Provides a data provider implementation for Google Spreadsheets.
public sealed class GoogleSpreadsheetsDataProvider : IDataProvider
- Inheritance
-
GoogleSpreadsheetsDataProvider
- Implements
- Inherited Members
Examples
The following example demonstrates how to use the GoogleSpreadsheetsDataProvider to export a report to PDF:
// Example 1: Access a public spreadsheet using API key
GoogleSpreadsheetsDataProvider publicProvider = new GoogleSpreadsheetsDataProvider(
"1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms", // Spreadsheet ID from URL
firstRowAreColumnNames: true,
apiKey: "your_api_key_here");
// Create a ListLabel reporting engine instance and assign the provider as the data source.
using ListLabel listLabel = new ListLabel();
listLabel.DataSource = publicProvider;
// Configure export settings to generate a PDF.
ExportConfiguration exportConfiguration = new ExportConfiguration(LlExportTarget.Pdf, exportFilePath, projectFilePath);
exportConfiguration.ShowResult = true;
// Export the report to PDF.
listLabel.Export(exportConfiguration);
// Example 2: Access a private spreadsheet using OAuth
GoogleSpreadsheetsDataProvider privateProvider = new GoogleSpreadsheetsDataProvider(
"1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
firstRowAreColumnNames: true,
refreshToken: "your_refresh_token",
clientId: "your_client_id.apps.googleusercontent.com",
clientSecret: "your_client_secret");
// Example 3: Access specific sheets only
List<string> sheetsToInclude = new List<string> { "Sales", "Customers", "Products" };
GoogleSpreadsheetsDataProvider filteredProvider = new GoogleSpreadsheetsDataProvider(
"1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
firstRowAreColumnNames: true,
sheetNames: sheetsToInclude.AsReadOnly(),
refreshToken: "your_refresh_token",
clientId: "your_client_id.apps.googleusercontent.com",
clientSecret: "your_client_secret");
// Example 4: Public spreadsheet with specific sheets
GoogleSpreadsheetsDataProvider publicFilteredProvider = new GoogleSpreadsheetsDataProvider(
"1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
firstRowAreColumnNames: true,
sheetNames: new List<string> { "Sheet1", "Sheet2" }.AsReadOnly(),
apiKey: "your_api_key_here");
Remarks
The GoogleSpreadsheetsDataProvider class implements IDataProvider to enable access to Google Sheets data through the Google Sheets API v4. The provider supports both public spreadsheets (using an API key) and private spreadsheets (using OAuth 2.0 authentication with refresh tokens). Each sheet in the spreadsheet becomes a table in the provider, with optional filtering to include only specific sheets. The first row can optionally be treated as column headers. Authentication tokens are automatically refreshed when needed. This provider is ideal for creating reports from spreadsheet data stored in Google Sheets, whether for collaborative data management, simple databases, or data collection scenarios. Public spreadsheets must be published to the web to be accessible without OAuth authentication.
Constructors
GoogleSpreadsheetsDataProvider(string, bool, ReadOnlyCollection<string>, string)
Initializes a new instance of the GoogleSpreadsheetsDataProvider class for a public spreadsheet (without OAuth authorization).
public GoogleSpreadsheetsDataProvider(string tableId, bool firstRowAreColumnNames, ReadOnlyCollection<string> sheetNames, string apiKey)
Parameters
tableIdstringThe identifier of the spreadsheet.
firstRowAreColumnNamesboolIf set to
true, the first row of each sheet contains column names.sheetNamesReadOnlyCollection<string>A collection of sheet names to include as tables. If
null, all sheets are included.apiKeystringThe API key used to access the public spreadsheet. This parameter must be provided.
Exceptions
- ArgumentException
Thrown if
apiKeyis empty.
GoogleSpreadsheetsDataProvider(string, bool, ReadOnlyCollection<string>, string, string, string)
Initializes a new instance of the GoogleSpreadsheetsDataProvider class using OAuth authorization.
public GoogleSpreadsheetsDataProvider(string tableId, bool firstRowAreColumnNames, ReadOnlyCollection<string> sheetNames, string refreshToken, string clientId, string clientSecret)
Parameters
tableIdstringThe identifier of the spreadsheet.
firstRowAreColumnNamesboolIf set to
true, the first row of each sheet contains column names.sheetNamesReadOnlyCollection<string>A collection of sheet names to include as tables. If
null, all sheets are included.refreshTokenstringThe OAuth refresh token.
clientIdstringThe OAuth client identifier.
clientSecretstringThe OAuth client secret.
GoogleSpreadsheetsDataProvider(string, bool, string)
Initializes a new instance of the GoogleSpreadsheetsDataProvider class for a public spreadsheet (without OAuth authorization).
public GoogleSpreadsheetsDataProvider(string tableId, bool firstRowAreColumnNames, string apiKey)
Parameters
tableIdstringThe identifier of the spreadsheet.
firstRowAreColumnNamesboolIf set to
true, the first row of each sheet contains column names.apiKeystringThe API key used to access the public spreadsheet. This parameter must be provided.
GoogleSpreadsheetsDataProvider(string, bool, string, string, string)
Initializes a new instance of the GoogleSpreadsheetsDataProvider class using OAuth authorization.
public GoogleSpreadsheetsDataProvider(string tableId, bool firstRowAreColumnNames, string refreshToken, string clientId, string clientSecret)
Parameters
tableIdstringThe identifier of the spreadsheet.
firstRowAreColumnNamesboolIf set to
true, the first row of each sheet contains column names.refreshTokenstringThe OAuth refresh token.
clientIdstringThe OAuth client identifier.
clientSecretstringThe OAuth client secret.
Properties
ApiKey
Gets the API key used for accessing public spreadsheets.
public string ApiKey { get; }
Property Value
ClientId
Gets the client identifier used for OAuth authorization.
public string ClientId { get; }
Property Value
FirstRowContainsColumnNames
Gets a value indicating whether the first row of each sheet contains column names.
public bool FirstRowContainsColumnNames { get; }
Property Value
RefreshToken
Gets the refresh token used for OAuth authorization.
public string RefreshToken { get; }
Property Value
SheetNames
Gets the names of sheets that should be included as tables.
public ReadOnlyCollection<string> SheetNames { get; }
Property Value
TableId
Gets the table identifier of the spreadsheet.
public string TableId { get; }