| Constructor and Description |
|---|
SpreadsheetDocument(com.google.api.services.sheets.v4.Sheets sheetsService,
String spreadsheetId)
Creates a new Spreadsheet document for Google Spreadsheet with given file ID.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
batchUpdate(Consumer<eu.easyrpa.openframework.google.sheets.internal.SpreadsheetUpdateRequestsBatch> action)
Allows to put a set of spreadsheet update requests into one batch.
|
void |
commit()
Sends all previously done changes to Google server and gets back the actual content of this spreadsheet
after applying these changes on Google side.
|
Sheet |
createSheet(String sheetName)
Creates a new sheet for this Spreadsheet document and return the high level
representation.
|
InputStream |
exportAsXLSX()
Gets content of this Spreadsheet document as XLSX file.
|
Sheet |
findSheet(MatchMethod matchMethod,
String... values)
Finds the sheet with a row that contains all given values and active it.
|
Sheet |
findSheet(String... values)
Finds the sheet with a row that contains all given values and active it.
|
Sheet |
getActiveSheet()
Gets current active sheet.
|
com.google.api.services.sheets.v4.model.Spreadsheet |
getGSpreadsheet()
Gets underlay Google object representing this spreadsheet.
|
String |
getId()
Gets unique identifier of this Spreadsheet document.
|
String |
getName()
Gets name for this Spreadsheet document.
|
List<String> |
getSheetNames()
Gets names of all sheets
|
com.google.api.services.sheets.v4.Sheets |
getSheetsService()
Gets Google Sheets service.
|
Iterator<Sheet> |
iterator() |
void |
reload()
Gets an actual Spreadsheet data from Google Drive.
|
void |
removeSheet(Sheet sheet)
Removes given sheet.
|
void |
removeSheet(String sheetName)
Removes sheet with the given name.
|
void |
rename(String name)
Renames this Spreadsheet document.
|
Sheet |
selectSheet(int index)
Sets the sheet with given index as active and return it.
|
Sheet |
selectSheet(String sheetName)
Sets the sheet with given name as active and return it.
|
void |
setAutoCommit(boolean isAutoCommit)
Sets automatic sending of change requests to Google server on/off.
|
void |
withOneBatch(Consumer<SpreadsheetDocument> action)
Collects all changes are done within given lambda and sends them as one batch to Google server in the end.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic SpreadsheetDocument(com.google.api.services.sheets.v4.Sheets sheetsService,
String spreadsheetId)
sheetsService - instance of related Google Spreadsheets service.spreadsheetId - the file ID of source spreadsheet in Google Drive.SpreadsheetException - in case of some errors during reading of spreadsheet with given ID from
Google Drive.public String getId()
public String getName()
public void rename(String name)
name - the new name to set.public InputStream exportAsXLSX()
public List<String> getSheetNames()
public Sheet createSheet(String sheetName)
sheetName - The name to set for the sheet.public void removeSheet(String sheetName)
sheetName - of the sheet to removepublic void removeSheet(Sheet sheet)
sheet - sheet to removepublic Sheet getActiveSheet()
public Sheet selectSheet(int index)
index - index of sheet that need to be activated.null if sheet with such index is absent.public Sheet selectSheet(String sheetName)
sheetName - name of sheet that need to be activated.null if sheet not found.public Sheet findSheet(String... values)
values - list of values to match.null if sheet not found.public Sheet findSheet(MatchMethod matchMethod, String... values)
matchMethod - method that defines how passed values are matched with each row values.values - list of values to match.null if sheet not found.MatchMethodpublic com.google.api.services.sheets.v4.model.Spreadsheet getGSpreadsheet()
public com.google.api.services.sheets.v4.Sheets getSheetsService()
public void reload()
public void setAutoCommit(boolean isAutoCommit)
By default any change of spreadsheet data using SpreadsheetDocument or related objects (Sheet, Row, Cell etc.) initiates sending of corresponding change requests to Google server. But when it's necessary to do a lot of such changes it's possibly to face with limitation of Google quotes. Since no more than 60 requests can be done per minute. See Sheets API Usage Limits for more details.
Using this method it's possible to switch off this behaviour and change requests won't be sent at all until
commit() method is invoked. The same goal can be achieved using method withOneBatch(Consumer).
...
SpreadsheetDocument doc = ...;
...
doc.setAutoCommit(false);
Sheet sheet = doc.getActiveSheet();
for(int i = 0; i < 100; i++){
// No one actual request will be sent to Google server.
// All changes will be done locally in memory.
sheet.setValue(i, 0, "Value" + i);
}
// Commit initiate sending of previously done changes to Google server as one batch.
doc.commit(); //or doc.setAutoCommit(true);
...
isAutoCommit - false to switch off automatic sending of change requests to Google server and
true vice versa. In case of true value it's additionally calls
commit() to insure that all previously done changes are sent to Google server.public void commit()
This method is actually working only after calling of setAutoCommit(false) or within
withOneBatch(Consumer). In other cases it does nothing.
public void withOneBatch(Consumer<SpreadsheetDocument> action)
Example:
...
doc.withOneBatch(d -> {
Sheet sheet = d.getActiveSheet();
for(int i = 0; i < 100; i++){
// No one actual request will be sent to Google server.
// All changes will be done locally in memory.
sheet.setValue(i, 0, "Value" + i);
}
}); // In the end of calling this method all done changes sent to Google
// server as one batch and the actual content of this spreadsheet
// is got back after applying these changes on Google side.
...
action - Consumer lambda expression that implements specific logic of changing
this SpreadsheetDocument.protected void batchUpdate(Consumer<eu.easyrpa.openframework.google.sheets.internal.SpreadsheetUpdateRequestsBatch> action)
action - Consumer lambda expression with SpreadsheetUpdateRequestsBatch as argument. Within
this lambda expression necessary update requests can be put into SpreadsheetUpdateRequestsBatch.Copyright © 2022. All rights reserved.