Class GoogleSheetDocument

java.lang.Object
com.northconcepts.datapipeline.google.sheets.GoogleSheetDocument

public class GoogleSheetDocument extends Object
A Google Sheets spreadsheet shared by GoogleSheetReader and GoogleSheetWriter. Open it with open(String), or createSpreadsheet(String) followed by open(), before use.
  • Field Details

    • JSON_FACTORY

      protected static final JsonFactory JSON_FACTORY
  • Constructor Details

    • GoogleSheetDocument

      public GoogleSheetDocument(Credential credentials, HttpTransport transport)
      The transport stays owned by the caller and is not shut down by close().
    • GoogleSheetDocument

      public GoogleSheetDocument(Credential credentials)
      Creates a trusted transport that close() shuts down.
  • Method Details

    • open

      public GoogleSheetDocument open()
    • open

      public GoogleSheetDocument open(String spreadsheetId)
      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

      public void close() throws DataException
      Forgets the spreadsheet; the transport is shut down only when this document created it.
      Throws:
      DataException
    • startReading

      public GoogleSheetDocument startReading(String range, String sheetName, int sheetIndex)
      Loads the sheet to read: the one a range names, else sheetName, else the sheet at sheetIndex. A range without a sheet prefix, such as A1:B3, is read from that resolved sheet rather than the first sheet.
    • startReadingSheet

      public GoogleSheetDocument startReadingSheet(String sheetName)
    • startReadingRange

      public GoogleSheetDocument startReadingRange(String range)
      Reads an A1-notation range such as Sheet1!A1:B3; without a sheet prefix the API reads the first sheet.
    • startReadingSheet

      public GoogleSheetDocument startReadingSheet(int sheetIndex)
    • readField

      public void readField(int rowIndex, int fieldIndex, Field field)
      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

      public GoogleSheetDocument appendRow(List<Object> row)
    • 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

      public GoogleSheetDocument createSpreadsheet(String title)
      Creates a new spreadsheet and remembers its id; follow with open().
    • getSpreadsheetId

      public String getSpreadsheetId()
    • setSpreadsheetId

      public GoogleSheetDocument setSpreadsheetId(String spreadsheetId)
      A bare id only (no URL), used by the next open().
    • getSpreadsheetUrl

      public String getSpreadsheetUrl()
    • getCredentials

      public Credential getCredentials()
    • getTransport

      public HttpTransport getTransport()
    • getCellValues

      public List<List<Object>> getCellValues()
      The values loaded by startReading, or the rows waiting to be flushed when writing.
    • getSheetNames

      public String[] getSheetNames()
      Titles of every sheet in position order; loaded by open(String).
    • getApplicationName

      public String getApplicationName()
    • setApplicationName

      public GoogleSheetDocument setApplicationName(String applicationName)
      Null restores the default; takes effect on the next open(String) or createSpreadsheet(String).
    • getValueRenderOption

      public String getValueRenderOption()
    • setValueRenderOption

      public GoogleSheetDocument 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) or FORMULA; null sends no option.
    • getDateTimeRenderOption

      public String getDateTimeRenderOption()
    • setDateTimeRenderOption

      public GoogleSheetDocument setDateTimeRenderOption(String dateTimeRenderOption)
      How date, time and duration cells are read under UNFORMATTED_VALUE: SERIAL_NUMBER (the API default) or FORMATTED_STRING; null sends no option.
    • getValueInputOption

      public String getValueInputOption()
    • setValueInputOption

      public GoogleSheetDocument setValueInputOption(String valueInputOption)
      How written cells are interpreted: RAW (the default) stores every value as sent, so dates arrive as text; USER_ENTERED parses 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

      public String getSheetName()
    • getRange

      public String getRange()
    • getSheetIndex

      public int getSheetIndex()
    • getFirstRowIndex

      public int getFirstRowIndex()
    • getFirstColumnIndex

      public int getFirstColumnIndex()
    • getRowsWritten

      public int getRowsWritten()