Class GoogleSheetDocument
java.lang.Object
com.northconcepts.datapipeline.google.sheets.GoogleSheetDocument
A Google Sheets spreadsheet shared by
GoogleSheetReader and GoogleSheetWriter. Open it with
open(String), or createSpreadsheet(String) followed by open(), before use.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGoogleSheetDocument(Credential credentials) Creates a trusted transport thatclose()shuts down.GoogleSheetDocument(Credential credentials, HttpTransport transport) The transport stays owned by the caller and is not shut down byclose(). -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Forgets the spreadsheet; the transport is shut down only when this document created it.createSpreadsheet(String title) Creates a new spreadsheet and remembers its id; follow withopen().voidSends the buffered rows to the next free rows of the block in one request and empties the buffer, whether or not the request succeeds; the sheet's grid is enlarged first when the rows would not fit.intintgetCellCount(int rowIndex) The values loaded bystartReading, or the rows waiting to be flushed when writing.CredentialintintintgetRange()intintString[]Titles of every sheet in position order; loaded byopen(String).HttpTransportbooleanisOpen()open()Connects to the spreadsheet, given as a bare id or a full docs.google.com URL, and loads its sheet list.voidCopies a cell into the field: numbers and booleans, which arrive only under the UNFORMATTED_VALUE render option, become DOUBLE and BOOLEAN as in Excel; other cells are strings; blank and missing cells leave the field untouched.setApplicationName(String applicationName) Null restores the default; takes effect on the nextopen(String)orcreateSpreadsheet(String).setDateTimeRenderOption(String dateTimeRenderOption) How date, time and duration cells are read underUNFORMATTED_VALUE:SERIAL_NUMBER(the API default) orFORMATTED_STRING; null sends no option.setSpreadsheetId(String spreadsheetId) A bare id only (no URL), used by the nextopen().setValueInputOption(String valueInputOption) How written cells are interpreted:RAW(the default) stores every value as sent, so dates arrive as text;USER_ENTEREDparses values as if typed into the UI, so date and time strings become date cells and a string starting with=becomes a formula.setValueRenderOption(String valueRenderOption) How cells are read:FORMATTED_VALUE(the API default, every cell a string as shown in the UI),UNFORMATTED_VALUE(numbers and booleans arrive typed) orFORMULA; null sends no option.startReading(String range, String sheetName, int sheetIndex) Loads the sheet to read: the one a range names, else sheetName, else the sheet at sheetIndex.startReadingRange(String range) Reads an A1-notation range such asSheet1!A1:B3; without a sheet prefix the API reads the first sheet.startReadingSheet(int sheetIndex) startReadingSheet(String sheetName) final voidstartWriting(String range, String sheetName, int sheetIndex, int firstRowIndex, int firstColumnIndex) Prepares the sheet to write, creating it when the name is new, and clears everything from the block's first cell to the sheet's bottom-right corner (or just the range).
-
Field Details
-
JSON_FACTORY
protected static final JsonFactory JSON_FACTORY
-
-
Constructor Details
-
Method Details
-
open
-
open
Connects to the spreadsheet, given as a bare id or a full docs.google.com URL, and loads its sheet list. -
isOpen
public boolean isOpen() -
close
Forgets the spreadsheet; the transport is shut down only when this document created it.- Throws:
DataException
-
startReading
Loads the sheet to read: the one a range names, else sheetName, else the sheet at sheetIndex. A range without a sheet prefix, such asA1:B3, is read from that resolved sheet rather than the first sheet. -
startReadingSheet
-
startReadingRange
Reads an A1-notation range such asSheet1!A1:B3; without a sheet prefix the API reads the first sheet. -
startReadingSheet
-
readField
Copies a cell into the field: numbers and booleans, which arrive only under the UNFORMATTED_VALUE render option, become DOUBLE and BOOLEAN as in Excel; other cells are strings; blank and missing cells leave the field untouched. -
getCellCount
public int getCellCount(int rowIndex) -
getLastRowIndex
public int getLastRowIndex() -
startWriting
public final void startWriting(String range, String sheetName, int sheetIndex, int firstRowIndex, int firstColumnIndex) Prepares the sheet to write, creating it when the name is new, and clears everything from the block's first cell to the sheet's bottom-right corner (or just the range). The sheet is the one a range names, else sheetName, else the sheet at sheetIndex; the block starts at the range's first cell, else at firstRowIndex/firstColumnIndex. -
appendRow
-
flushRows
public void flushRows()Sends the buffered rows to the next free rows of the block in one request and empties the buffer, whether or not the request succeeds; the sheet's grid is enlarged first when the rows would not fit. -
getBufferedRowCount
public int getBufferedRowCount() -
createSpreadsheet
Creates a new spreadsheet and remembers its id; follow withopen(). -
getSpreadsheetId
-
setSpreadsheetId
A bare id only (no URL), used by the nextopen(). -
getSpreadsheetUrl
-
getCredentials
public Credential getCredentials() -
getTransport
public HttpTransport getTransport() -
getCellValues
The values loaded bystartReading, or the rows waiting to be flushed when writing. -
getSheetNames
Titles of every sheet in position order; loaded byopen(String). -
getApplicationName
-
setApplicationName
Null restores the default; takes effect on the nextopen(String)orcreateSpreadsheet(String). -
getValueRenderOption
-
setValueRenderOption
How cells are read:FORMATTED_VALUE(the API default, every cell a string as shown in the UI),UNFORMATTED_VALUE(numbers and booleans arrive typed) orFORMULA; null sends no option. -
getDateTimeRenderOption
-
setDateTimeRenderOption
How date, time and duration cells are read underUNFORMATTED_VALUE:SERIAL_NUMBER(the API default) orFORMATTED_STRING; null sends no option. -
getValueInputOption
-
setValueInputOption
How written cells are interpreted:RAW(the default) stores every value as sent, so dates arrive as text;USER_ENTEREDparses values as if typed into the UI, so date and time strings become date cells and a string starting with=becomes a formula. Null restores RAW. -
getSheetName
-
getRange
-
getSheetIndex
public int getSheetIndex() -
getFirstRowIndex
public int getFirstRowIndex() -
getFirstColumnIndex
public int getFirstColumnIndex() -
getRowsWritten
public int getRowsWritten()
-