Class: Cosmos::ExcelSpreadsheet::ExcelWorksheet
- Defined in:
- lib/cosmos/win32/excel.rb
Overview
Class to allow easy manipulation to the data in an Excel worksheet
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#num_columns ⇒ Object
readonly
Returns the value of attribute num_columns.
-
#num_rows ⇒ Object
readonly
Returns the value of attribute num_rows.
Instance Method Summary collapse
-
#[](index) ⇒ ExcelWorksheet
Access the lookup values by string or the raw data by index.
-
#initialize(worksheet) ⇒ ExcelWorksheet
constructor
A new instance of ExcelWorksheet.
- #keys ⇒ Object
Constructor Details
#initialize(worksheet) ⇒ ExcelWorksheet
Returns a new instance of ExcelWorksheet.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cosmos/win32/excel.rb', line 24 def initialize(worksheet) @name = worksheet.name @num_rows = worksheet.UsedRange.rows.count @num_columns = worksheet.UsedRange.columns.count # Get Excel Data from Worksheet @data = worksheet.UsedRange.value # Build a lookup table based on the first column @lkup = {} if @data @data.each do |row| @lkup[row[0]] = row[1..-1] end end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
21 22 23 |
# File 'lib/cosmos/win32/excel.rb', line 21 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
21 22 23 |
# File 'lib/cosmos/win32/excel.rb', line 21 def name @name end |
#num_columns ⇒ Object (readonly)
Returns the value of attribute num_columns.
21 22 23 |
# File 'lib/cosmos/win32/excel.rb', line 21 def num_columns @num_columns end |
#num_rows ⇒ Object (readonly)
Returns the value of attribute num_rows.
21 22 23 |
# File 'lib/cosmos/win32/excel.rb', line 21 def num_rows @num_rows end |
Instance Method Details
#[](index) ⇒ ExcelWorksheet
Access the lookup values by string or the raw data by index
49 50 51 52 53 54 55 |
# File 'lib/cosmos/win32/excel.rb', line 49 def [](index) if index.is_a? String @lkup[index] else @data[index] end end |
#keys ⇒ Object
41 42 43 |
# File 'lib/cosmos/win32/excel.rb', line 41 def keys @lkup.keys end |