Class: Princess::ExcelReader
- Inherits:
-
Object
- Object
- Princess::ExcelReader
- Defined in:
- lib/princess/excel_reader.rb
Instance Method Summary collapse
-
#active_sheet(sheet_num) ⇒ Object
load a sheet for reading.
-
#cell(coord) ⇒ Object
return the specified cell content.
-
#each ⇒ Object
iterate through the spreadsheet rows.
-
#initialize(filename, default_sheet = 0) ⇒ ExcelReader
constructor
A new instance of ExcelReader.
-
#row(num) ⇒ Object
return the specified row.
Constructor Details
#initialize(filename, default_sheet = 0) ⇒ ExcelReader
Returns a new instance of ExcelReader.
4 5 6 7 |
# File 'lib/princess/excel_reader.rb', line 4 def initialize(filename, default_sheet = 0) @book = Spreadsheet.open(filename) @sheet = @book.worksheet(default_sheet) end |
Instance Method Details
#active_sheet(sheet_num) ⇒ Object
load a sheet for reading
10 11 12 13 |
# File 'lib/princess/excel_reader.rb', line 10 def active_sheet(sheet_num) raise 'invalid argument' if !sheet_num.is_a?(Integer) @sheet = @book.worksheet(sheet_num) end |
#cell(coord) ⇒ Object
return the specified cell content
29 30 31 |
# File 'lib/princess/excel_reader.rb', line 29 def cell(coord) row(coord.scan(/\d+/).first.to_i).cell(coord.scan(/\D+/).first) end |