class RobustExcelOle::TableRow
Constants
- Value
Attributes
ole_object[R]
ole_tablerow[R]
Public Class Methods
new(rownumber_or_oletablerow)
click to toggle source
# File lib/robust_excel_ole/list_row.rb, line 12 def initialize(rownumber_or_oletablerow) @ole_tablerow = if rownumber_or_oletablerow.is_a?(ListRow) rownumber_or_oletablerow.ole_tablerow else begin rownumber_or_oletablerow.Parent.send(:ListRows) rownumber_or_oletablerow rescue ole_table.ListRows.Item(rownumber_or_oletablerow) end end end
Public Instance Methods
==(other_listrow)
click to toggle source
# File lib/robust_excel_ole/list_row.rb, line 94 def == other_listrow other_listrow.is_a?(ListRow) && other_listrow.values == self.values end
[](column_number_or_name)
click to toggle source
returns the value of the cell with given column name or number @param [Variant] column number or column name @return [Variant] value of the cell
# File lib/robust_excel_ole/list_row.rb, line 28 def [] column_number_or_name ole_cell = ole_table.Application.Intersect( @ole_tablerow.Range, ole_table.ListColumns.Item(column_number_or_name).Range) value = ole_cell.Value value.respond_to?(:gsub) ? value.encode('utf-8') : value rescue WIN32OLERuntimeError raise TableRowError, "could not determine the value at column #{column_number_or_name}\n#{$!.message}" end
[]=(column_number_or_name, value)
click to toggle source
sets the value of the cell with given column name or number @param [Variant] column number or column name @param [Variant] value of the cell
# File lib/robust_excel_ole/list_row.rb, line 40 def []=(column_number_or_name, value) begin ole_cell = ole_table.Application.Intersect( @ole_tablerow.Range, ole_table.ListColumns.Item(column_number_or_name).Range) ole_cell.Value = value rescue WIN32OLERuntimeError raise TableRowError, "could not assign value #{value.inspect} to cell at column #{column_number_or_name}\n#{$!.message}" end end
delete_values()
click to toggle source
deletes the values of the row
# File lib/robust_excel_ole/list_row.rb, line 87 def delete_values @ole_tablerow.Range.Value = [[].fill(nil,0..(ole_table.ListColumns.Count)-1)] nil rescue WIN32OLERuntimeError raise TableError, "could not delete values\n#{$!.message}" end
inspect()
click to toggle source
@private
# File lib/robust_excel_ole/list_row.rb, line 125 def inspect "#<ListRow: index:#{@ole_tablerow.Index} size:#{ole_table.ListColumns.Count} #{ole_table.Name}>" end
keys_values()
click to toggle source
key-value pairs of the row @return [Hash] key-value pairs of the row
# File lib/robust_excel_ole/list_row.rb, line 78 def keys_values ole_table.column_names.zip(values).to_h end
Also aliased as: to_h
method_missing(name, *args)
click to toggle source
Calls superclass method
# File lib/robust_excel_ole/list_row.rb, line 98 def method_missing(name, *args) # this should not happen: raise(TableRowError, "internal error: ole_table not defined") unless self.class.method_defined?(:ole_table) name_str = name.to_s core_name = name_str.chomp('=') column_names = ole_table.HeaderRowRange.Value.first column_name = column_names.find do |c| c == core_name || c.gsub(/\W/,'_') == core_name || c.underscore == core_name || c.underscore.gsub(/\W/,'_') == core_name || c.replace_umlauts.gsub(/\W/,'_') == core_name || c.replace_umlauts.underscore.gsub(/\W/,'_') == core_name end if column_name define_and_call_method(column_name, name, *args) else super(name, *args) end end
to_s()
click to toggle source
@private
# File lib/robust_excel_ole/list_row.rb, line 120 def to_s inspect end
values()
click to toggle source
values of the row @return [Array] values of the row
# File lib/robust_excel_ole/list_row.rb, line 52 def values value = @ole_tablerow.Range.Value return value if value==[nil] value = if !value.respond_to?(:pop) [value] elsif value.first.respond_to?(:pop) value.first end value.map{|v| v.respond_to?(:gsub) ? v.encode('utf-8') : v} rescue WIN32OLERuntimeError raise TableError, "could not read values\n#{$!.message}" end
Also aliased as: to_a
values=(values)
click to toggle source
sets the values of the row @param [Array] values of the row
# File lib/robust_excel_ole/list_row.rb, line 67 def values= values updated_values = self.values updated_values[0,values.length] = values @ole_tablerow.Range.Value = [updated_values] values rescue WIN32OLERuntimeError raise TableError, "could not set values #{values.inspect}\n#{$!.message}" end
Also aliased as: set_values
Private Instance Methods
define_and_call_method(column_name,method_name,*args)
click to toggle source
# File lib/robust_excel_ole/list_row.rb, line 131 def define_and_call_method(column_name,method_name,*args) #column_name = column_name.force_encoding('cp850') ole_cell = ole_table.Application.Intersect( @ole_tablerow.Range, ole_table.ListColumns.Item(column_name).Range) define_getting_setting_method(ole_cell,method_name) self.send(method_name, *args) end
define_getting_setting_method(ole_cell,name)
click to toggle source
# File lib/robust_excel_ole/list_row.rb, line 139 def define_getting_setting_method(ole_cell,name) if name[-1] != '=' self.class.define_method(name) do ole_cell.Value end else self.class.define_method(name) do |value| ole_cell.Value = value end end end