class GoogleDrive::Spreadsheet

A spreadsheet.

e.g., Use methods spreadsheet_by_title, spreadsheet_by_url, create_spreadsheet in GoogleDrive::Session to get GoogleDrive::Spreadsheet object.

Constants

SUPPORTED_EXPORT_FORMAT

Public Instance Methods

add_worksheet(title, max_rows = 100, max_cols = 20, index: nil) click to toggle source

Adds a new worksheet to the spreadsheet. Returns added GoogleDrive::Worksheet.

When index is specified, the worksheet is inserted at the given index.

# File lib/google_drive/spreadsheet.rb, line 79
def add_worksheet(title, max_rows = 100, max_cols = 20, index: nil)
  (response,) = batch_update([{
    add_sheet: {
      properties: {
        title: title,
        index: index,
        grid_properties: {
          row_count: max_rows,
          column_count: max_cols,
        },
      },
    },
  }])
  Worksheet.new(@session, self, response.add_sheet.properties)
end
batch_update(requests) click to toggle source

Performs batch update of the spreadsheet.

requests is an Array of Google::Apis::SheetsV4::Request or its Hash equivalent. Returns an Array of Google::Apis::SheetsV4::Response.

# File lib/google_drive/spreadsheet.rb, line 126
def batch_update(requests)
  batch_request =
    Google::Apis::SheetsV4::BatchUpdateSpreadsheetRequest.new(
      requests: requests)
  batch_response =
    @session.sheets_service.batch_update_spreadsheet(id, batch_request)
  batch_response.replies
end
document_feed_url() click to toggle source

URL of feed used in the deprecated document list feed API.

# File lib/google_drive/spreadsheet.rb, line 40
def document_feed_url
  'https://docs.google.com/feeds/documents/private/full/' +
    CGI.escape(resource_id)
end
download_to_file(_path, _params = {}) click to toggle source

Not available for GoogleDrive::Spreadsheet. Use export_as_file instead.

# File lib/google_drive/spreadsheet.rb, line 96
def download_to_file(_path, _params = {})
  raise(
    NotImplementedError,
    'download_to_file is not available for GoogleDrive::Spreadsheet. ' \
    'Use export_as_file instead.'
  )
end
download_to_io(_io, _params = {}) click to toggle source

Not available for GoogleDrive::Spreadsheet. Use export_to_io instead.

# File lib/google_drive/spreadsheet.rb, line 114
def download_to_io(_io, _params = {})
  raise(
    NotImplementedError,
    'download_to_io is not available for GoogleDrive::Spreadsheet. ' \
    'Use export_to_io instead.'
  )
end
download_to_string(_params = {}) click to toggle source

Not available for GoogleDrive::Spreadsheet. Use export_as_string instead.

# File lib/google_drive/spreadsheet.rb, line 105
def download_to_string(_params = {})
  raise(
    NotImplementedError,
    'download_to_string is not available for GoogleDrive::Spreadsheet. ' \
    'Use export_as_string instead.'
  )
end
key() click to toggle source

Key of the spreadsheet.

# File lib/google_drive/spreadsheet.rb, line 28
def key
  id
end
spreadsheet_feed_url() click to toggle source

Spreadsheet feed URL of the spreadsheet.

# File lib/google_drive/spreadsheet.rb, line 46
def spreadsheet_feed_url
  'https://spreadsheets.google.com/feeds/spreadsheets/private/full/' + id
end
worksheet_by_gid(sheet_id)
worksheet_by_sheet_id(sheet_id) click to toggle source

Returns a GoogleDrive::Worksheet with the given gid.

Returns nil if not found.

# File lib/google_drive/spreadsheet.rb, line 67
def worksheet_by_sheet_id(sheet_id)
  sheet_id = sheet_id.to_i
  worksheets.find { |ws| ws.sheet_id == sheet_id }
end
Also aliased as: worksheet_by_gid
worksheet_by_title(title) click to toggle source

Returns a GoogleDrive::Worksheet with the given title in the spreadsheet.

Returns nil if not found. Returns the first one when multiple worksheets with the title are found.

# File lib/google_drive/spreadsheet.rb, line 60
def worksheet_by_title(title)
  worksheets.find { |ws| ws.title == title }
end
worksheets() click to toggle source

Returns worksheets of the spreadsheet as array of GoogleDrive::Worksheet.

# File lib/google_drive/spreadsheet.rb, line 51
def worksheets
  api_spreadsheet = @session.sheets_service.get_spreadsheet(id, fields: 'sheets.properties')
  api_spreadsheet.sheets.map{ |s| Worksheet.new(@session, self, s.properties) }
end
worksheets_feed_url() click to toggle source

URL of worksheet-based feed of the spreadsheet.

# File lib/google_drive/spreadsheet.rb, line 33
def worksheets_feed_url
  format(
    'https://spreadsheets.google.com/feeds/worksheets/%s/private/full', id
  )
end