Class GoogleSheets
Provides an interface for syncing localization data to a Google Sheet.
Namespace: UnityEditor.Localization.Plugins.Google
Syntax
public class GoogleSheets
Constructors
GoogleSheets(IGoogleSheetsService)
Creates a new instance of a GoogleSheets connection.
Declaration
public GoogleSheets(IGoogleSheetsService provider)
Parameters
Type | Name | Description |
---|---|---|
IGoogleSheetsService | provider | The Google Sheets service provider. See SheetsServiceProvider for a default implementation. |
Properties
SheetsService
The sheets provider is responsible for providing the SheetsService and configuring the type of access. SheetsServiceProvider.
Declaration
public IGoogleSheetsService SheetsService { get; }
Property Value
Type | Description |
---|---|
IGoogleSheetsService |
SpreadSheetId
The Id of the Google Sheet. This can be found by examining the url: https://docs.google.com/spreadsheets/d/>SpreadsheetId/edit#gid=SheetId Further information can be found here.
Declaration
public string SpreadSheetId { get; set; }
Property Value
Type | Description |
---|---|
String |
UsingApiKey
Declaration
protected virtual bool UsingApiKey { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
AddSheet(String, NewSheetProperties)
Creates a new sheet within the Spreadsheet with the id SpreadSheetId.
Declaration
public int AddSheet(string title, NewSheetProperties newSheetProperties)
Parameters
Type | Name | Description |
---|---|---|
String | title | The title for the new sheet |
NewSheetProperties | newSheetProperties |
Returns
Type | Description |
---|---|
Int32 | The new sheet id. |
CreateSpreadsheet(String, String, NewSheetProperties, ITaskReporter)
Creates a new Google Spreadsheet.
Declaration
public (string spreadSheetId, int sheetId) CreateSpreadsheet(string spreadSheetTitle, string sheetTitle, NewSheetProperties newSheetProperties, ITaskReporter reporter = null)
Parameters
Type | Name | Description |
---|---|---|
String | spreadSheetTitle | The title of the Spreadsheet. |
String | sheetTitle | |
NewSheetProperties | newSheetProperties | |
ITaskReporter | reporter | Optional reporter to display the progress and status of the task. |
Returns
Type | Description |
---|---|
ValueTuple<String, Int32> | Returns the new Spreadsheet and sheet id. |
ExecuteRequest<TResponse, TClientServiceRequest>(TClientServiceRequest)
Declaration
protected virtual TResponse ExecuteRequest<TResponse, TClientServiceRequest>(TClientServiceRequest req)
where TClientServiceRequest : ClientServiceRequest<TResponse>
Parameters
Type | Name | Description |
---|---|---|
TClientServiceRequest | req |
Returns
Type | Description |
---|---|
TResponse |
Type Parameters
Name | Description |
---|---|
TResponse | |
TClientServiceRequest |
ExecuteRequestAsync<TResponse, TClientServiceRequest>(TClientServiceRequest)
Declaration
protected virtual Task<TResponse> ExecuteRequestAsync<TResponse, TClientServiceRequest>(TClientServiceRequest req)
where TClientServiceRequest : ClientServiceRequest<TResponse>
Parameters
Type | Name | Description |
---|---|---|
TClientServiceRequest | req |
Returns
Type | Description |
---|---|
Task<TResponse> |
Type Parameters
Name | Description |
---|---|
TResponse | |
TClientServiceRequest |
GetColumnTitles(Int32)
Returns all the column titles(values from the first row) for the selected sheet inside of the Spreadsheet with id SpreadSheetId. This method requires the SheetsService to use OAuth authorization as it uses a data filter which reuires elevated authorization.
Declaration
public IList<string> GetColumnTitles(int sheetId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sheetId | The sheet id. |
Returns
Type | Description |
---|---|
IList<String> | All the |
GetRowCount(Int32)
Returns the total number of rows in the sheet inside of the Spreadsheet with id SpreadSheetId. This method requires the SheetsService to use OAuth authorization as it uses a data filter which reuires elevated authorization.
Declaration
public int GetRowCount(int sheetId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sheetId | The sheet to get the row count from. |
Returns
Type | Description |
---|---|
Int32 | The row count for the sheet. |
GetRowCountAsync(Int32)
Asynchronous version of GetRowCount(Int32)
Declaration
public Task<int> GetRowCountAsync(int sheetId)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sheetId | The sheet to get the row count from |
Returns
Type | Description |
---|---|
Task<Int32> | The row count for the sheet. |
GetSheets()
Returns a list of all the sheets in the Spreadsheet with the id SpreadSheetId.
Declaration
public List<(string name, int id)> GetSheets()
Returns
Type | Description |
---|---|
List<ValueTuple<String, Int32>> | The sheets names and id's. |
OpenSheetInBrowser(String)
Opens the spreadsheet in a browser.
Declaration
public static void OpenSheetInBrowser(string spreadSheetId)
Parameters
Type | Name | Description |
---|---|---|
String | spreadSheetId |
OpenSheetInBrowser(String, Int32)
Opens the spreadsheet with the sheet selected in a browser.
Declaration
public static void OpenSheetInBrowser(string spreadSheetId, int sheetId)
Parameters
Type | Name | Description |
---|---|---|
String | spreadSheetId | |
Int32 | sheetId |
PullIntoStringTableCollection(Int32, StringTableCollection, IList<SheetColumn>, Boolean, ITaskReporter, Boolean)
Pulls data from the Spreadsheet with id SpreadSheetId and uses columnMapping
to populate the collection
.
Declaration
public void PullIntoStringTableCollection(int sheetId, StringTableCollection collection, IList<SheetColumn> columnMapping, bool removeMissingEntries = false, ITaskReporter reporter = null, bool createUndo = false)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sheetId | The sheet(Spreadsheet tab) to pull the data from. |
StringTableCollection | collection | The collection to insert the data into. |
IList<SheetColumn> | columnMapping | The column mappings control what data will be extracted for each column of the sheet. The list must contain 1 IPullKeyColumn. |
Boolean | removeMissingEntries | After a pull has completed any keys that exist in the |
ITaskReporter | reporter | Optional reporter to display the progress and status of the task. |
Boolean | createUndo | Should an Undo be recorded so any changes can be reverted? |
PushStringTableCollection(Int32, StringTableCollection, IList<SheetColumn>, ITaskReporter)
Extracts data from collection
using columnMapping
and sends it to the sheet
inside of the Spreadsheet with id SpreadSheetId.
This method requires the SheetsService to use OAuth authorization as an API Key does not have the ability to write to a sheet.
Declaration
public void PushStringTableCollection(int sheetId, StringTableCollection collection, IList<SheetColumn> columnMapping, ITaskReporter reporter = null)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sheetId | The sheet(Spreadsheet tab) to insert the data into. |
StringTableCollection | collection | The collection to extract the data from. |
IList<SheetColumn> | columnMapping | The column mappings control what data will be extracted for each column of the sheet. The list must contain 1 KeyColumn. |
ITaskReporter | reporter | Optional reporter to display the progress and status of the task. |
PushStringTableCollectionAsync(Int32, StringTableCollection, IList<SheetColumn>, ITaskReporter)
Asynchronous version of PushStringTableCollection(Int32, StringTableCollection, IList<SheetColumn>, ITaskReporter)
Declaration
public Task PushStringTableCollectionAsync(int sheetId, StringTableCollection collection, IList<SheetColumn> columnMapping, ITaskReporter reporter = null)
Parameters
Type | Name | Description |
---|---|---|
Int32 | sheetId | The sheet(Spreadsheet tab) to insert the data into. |
StringTableCollection | collection | The collection to extract the data from. |
IList<SheetColumn> | columnMapping | The column mappings control what data will be extracted for each column of the sheet. The list must contain 1 KeyColumn. |
ITaskReporter | reporter | Optional reporter to display the progress and status of the task. |
Returns
Type | Description |
---|---|
Task |
SendBatchUpdateRequest(String, Request[])
Declaration
protected virtual BatchUpdateSpreadsheetResponse SendBatchUpdateRequest(string spreadsheetId, params Request[] requests)
Parameters
Type | Name | Description |
---|---|---|
String | spreadsheetId | |
Request[] | requests |
Returns
Type | Description |
---|---|
BatchUpdateSpreadsheetResponse |
SendBatchUpdateRequest(String, IList<Request>)
Declaration
protected virtual BatchUpdateSpreadsheetResponse SendBatchUpdateRequest(string spreadsheetId, IList<Request> requests)
Parameters
Type | Name | Description |
---|---|---|
String | spreadsheetId | |
IList<Request> | requests |
Returns
Type | Description |
---|---|
BatchUpdateSpreadsheetResponse |
SendBatchUpdateRequestAsync(String, IList<Request>)
Declaration
protected virtual Task<BatchUpdateSpreadsheetResponse> SendBatchUpdateRequestAsync(string spreadsheetId, IList<Request> requests)
Parameters
Type | Name | Description |
---|---|---|
String | spreadsheetId | |
IList<Request> | requests |
Returns
Type | Description |
---|---|
Task<BatchUpdateSpreadsheetResponse> |