Class: SpreadsheetGoodies::GoogleDrive::Worksheet

Inherits:
AbstractBaseWorksheet show all
Defined in:
lib/spreadsheet_goodies/google_drive/worksheet.rb

Instance Attribute Summary

Attributes inherited from AbstractBaseWorksheet

#header_row, #rows

Instance Method Summary collapse

Methods inherited from AbstractBaseWorksheet

#[], #data_rows, #find_row_by_column_value

Constructor Details

#initialize(spreadsheet_key, worksheet_title = nil, num_header_rows = 1) ⇒ Worksheet

Returns a new instance of Worksheet.

Parameters:

  • spreadsheet_key (String)

    Spreadsheet identifier, which can be retrieved from the spreasheet’s url

  • worksheet_title_or_index (String)

    Sheet name; if unspecified, the first sheet will be used.

  • num_header_rows (Integer) (defaults to: 1)

    Number of rows at the top of the sheet that contain headers or stuff other than data. Optional; if unspecified, assumes that a single top row contains the header and all rows below are data.



18
19
20
21
22
23
24
# File 'lib/spreadsheet_goodies/google_drive/worksheet.rb', line 18

def initialize(spreadsheet_key, worksheet_title=nil, num_header_rows=1)
  @spreadsheet_key = spreadsheet_key
  @worksheet_title = worksheet_title
  @num_header_rows = num_header_rows

  read_from_google_drive
end

Instance Method Details

#commit_writes!Object

Commit writes so they are propagated to the real spreadsheet



34
35
36
# File 'lib/spreadsheet_goodies/google_drive/worksheet.rb', line 34

def commit_writes!
  underlying_adapter_worksheet.save
end

#write_to_cell(row_index, col_index, value) ⇒ Object

Writes to a given cell identified by row and column indexes (they start at 1)



28
29
30
# File 'lib/spreadsheet_goodies/google_drive/worksheet.rb', line 28

def write_to_cell(row_index, col_index, value)
  underlying_adapter_worksheet[row_index, col_index] = value
end