Class GoogleSheetWriter


public class GoogleSheetWriter extends AbstractWriter
Writes records to one sheet of a Google Sheets spreadsheet opened as a GoogleSheetDocument, creating the sheet when its name is new and clearing the target block first. Values are sent in batches of setBatchSize(int) rows; nulls become empty cells and dates, times and binary values are written as text.
  • Field Details

  • Constructor Details

  • Method Details

    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Endpoint
      Adds this endpoint's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Overrides:
      addExceptionProperties in class AbstractWriter
    • open

      public void open()
      Description copied from class: DataEndpoint
      Makes this endpoint ready for reading or writing.
      Overrides:
      open in class AbstractWriter
    • close

      public void close()
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class DataEndpoint
    • writeRecord

      protected void writeRecord(Record record) throws Throwable
      Description copied from class: AbstractWriter
      Writes one row; called first for the header row (see AbstractWriter.isHeaderRow()) when field names are written, then for each record.
      Specified by:
      writeRecord in class AbstractWriter
      Throws:
      Throwable
    • getDocument

      public GoogleSheetDocument getDocument()
    • setAutoCloseDocument

      public GoogleSheetWriter setAutoCloseDocument(boolean autoCloseDocument)
      Indicates if the GoogleSheetDocument should be closed when this endpoint is closed. The default is false.
    • isAutoCloseDocument

      public boolean isAutoCloseDocument()
      Indicates if the GoogleSheetDocument should be closed when this endpoint is closed. The default is false.
    • getSheetName

      public String getSheetName()
    • setSheetName

      public GoogleSheetWriter setSheetName(String sheetName)
      Sets the name of the sheet to write, reusing an existing sheet by that name or creating it; when set, it is used instead of the sheet index (default is null).
    • getSheetIndex

      public int getSheetIndex()
    • setSheetIndex

      public GoogleSheetWriter setSheetIndex(int sheetIndex)
      Sets the 0-based index of the sheet to write when no sheet name or range names one (defaults to 0).
    • getFirstColumnIndex

      public int getFirstColumnIndex()
    • setFirstColumnIndex

      public GoogleSheetWriter setFirstColumnIndex(int firstColumnIndex)
      Sets the 0-based column that each record's first field is written to when no range is set (defaults to 0).
    • getFirstRowIndex

      public int getFirstRowIndex()
    • setFirstRowIndex

      public GoogleSheetWriter setFirstRowIndex(int firstRowIndex)
      Sets the 0-based row that the first record (or the header row) is written to when no range is set (defaults to 0).
    • getRange

      public String getRange()
    • setRange

      public GoogleSheetWriter setRange(String range)
      Sets the A1-notation range to write, such as A1:B3 or Sheet1!A1:B3; its first cell replaces the first row and column indexes and only that range is cleared (default is null).
    • getBatchSize

      public int getBatchSize()
    • setBatchSize

      public GoogleSheetWriter setBatchSize(int batchSize)
      Sets the number of rows sent per Sheets API request (default 500); any rows still buffered are sent by close().
    • setFieldNamesInFirstRow

      public GoogleSheetWriter setFieldNamesInFirstRow(boolean fieldNamesInFirstRow)
      Description copied from class: AbstractWriter
      Indicates if a header row of field names is written before the first record (default is true); must be called before AbstractWriter.open().
      Overrides:
      setFieldNamesInFirstRow in class AbstractWriter
    • setDescription

      public GoogleSheetWriter setDescription(String description)
      Description copied from class: Endpoint
      Sets the optional text shown for this endpoint in Endpoint.toString() and exception properties.
      Overrides:
      setDescription in class Endpoint