Class: RubyExcel::Row

Inherits:
Section show all
Defined in:
lib/rubyexcel/section.rb

Overview

A Row in the Sheet

Instance Attribute Summary collapse

Attributes inherited from Section

#data, #sheet

Instance Method Summary collapse

Methods inherited from Section

#<<, #cell, #delete, #each, #each_cell, #each_cell_without_headers, #each_without_headers, #empty?, #find, #inspect, #last_cell, #map!, #map_without_headers!, #read, #summarise, #to_s, #write

Methods included from Address

#address_to_col_index, #address_to_indices, #col_index, #col_letter, #column_id, #expand, #indices_to_address, #multi_array?, #offset, #row_id, #to_range_address

Constructor Details

#initialize(sheet, idx) ⇒ Row

Creates a RubyExcel::Row instance

Parameters:

  • sheet (RubyExcel::Sheet)

    the Sheet which holds this Row

  • idx (Fixnum)

    the index of this Row



229
230
231
232
# File 'lib/rubyexcel/section.rb', line 229

def initialize( sheet, idx )
  @idx = idx.to_i
  super( sheet )
end

Instance Attribute Details

#idxFixnum (readonly)

the Row index

Returns:

  • (Fixnum)

    the current value of idx



218
219
220
# File 'lib/rubyexcel/section.rb', line 218

def idx
  @idx
end

#lengthFixnum (readonly)

the Row length

Returns:

  • (Fixnum)

    the current value of length



218
219
220
# File 'lib/rubyexcel/section.rb', line 218

def length
  @length
end

Instance Method Details

#cell_by_header(header) ⇒ RubyExcel::Element Also known as: cell_h

Access a cell by its header

Parameters:

  • header (String)

    the header to search for

Returns:



241
242
243
# File 'lib/rubyexcel/section.rb', line 241

def cell_by_header( header )
  cell( getref( header ) )
end

#getref(header) ⇒ String

Find the Address of a header

Parameters:

  • header (String)

    the header to search for

Returns:

  • (String)

    the address of the header



253
254
255
256
257
258
259
# File 'lib/rubyexcel/section.rb', line 253

def getref( header )
  sheet.header_rows.times do |t|
    res = sheet.row( t + 1 ).find &/^#{header}$/
    return column_id( res ) if res
  end
  fail ArgumentError, 'Invalid header: ' + header.to_s
end

#value_by_header(header) ⇒ Object Also known as: val

Find a value in this Row by its header

Parameters:

  • header (String)

    the header to search for

Returns:

  • (Object)

    the value at the address



272
273
274
# File 'lib/rubyexcel/section.rb', line 272

def value_by_header( header )
  self[ getref( header ) ]
end