Class: OpenC3::ExcelSpreadsheet::ExcelWorksheet

Inherits:
Object
  • Object
show all
Defined in:
lib/openc3/win32/excel.rb

Overview

Class to allow easy manipulation to the data in an Excel worksheet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worksheet) ⇒ ExcelWorksheet

Returns a new instance of ExcelWorksheet.

Parameters:

  • worksheet (WIN32OLE)

    The underlying Excel worksheet object



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

#dataObject (readonly)

Returns the value of attribute data.



33
34
35
# File 'lib/openc3/win32/excel.rb', line 33

def data
  @data
end

#nameObject (readonly)

Returns the value of attribute name.



33
34
35
# File 'lib/openc3/win32/excel.rb', line 33

def name
  @name
end

#num_columnsObject (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_rowsObject (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

Parameters:

  • index (String|Integer)

    Name of the first column or index

Returns:



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

#keysObject



53
54
55
# File 'lib/openc3/win32/excel.rb', line 53

def keys
  @lkup.keys
end