Class: OpenC3::ExcelSpreadsheet::ExcelWorksheet
- Defined in:
- lib/openc3/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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/openc3/win32/excel.rb', line 36 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.
33 34 35 |
# File 'lib/openc3/win32/excel.rb', line 33 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
33 34 35 |
# File 'lib/openc3/win32/excel.rb', line 33 def name @name end |
#num_columns ⇒ Object (readonly)
Returns the value of attribute num_columns.
33 34 35 |
# File 'lib/openc3/win32/excel.rb', line 33 def num_columns @num_columns end |
#num_rows ⇒ Object (readonly)
Returns the value of attribute num_rows.
33 34 35 |
# File 'lib/openc3/win32/excel.rb', line 33 def num_rows @num_rows end |
Instance Method Details
#[](index) ⇒ ExcelWorksheet
Access the lookup values by string or the raw data by index
61 62 63 64 65 66 67 |
# File 'lib/openc3/win32/excel.rb', line 61 def [](index) if index.is_a? String @lkup[index] else @data[index] end end |
#keys ⇒ Object
53 54 55 |
# File 'lib/openc3/win32/excel.rb', line 53 def keys @lkup.keys end |