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



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

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

Instance Attribute Details

#idxObject (readonly) Also known as: index

The Row number



203
204
205
# File 'lib/rubyexcel/section.rb', line 203

def idx
  @idx
end

#lengthObject (readonly)

The number of Columns in the Row



203
204
205
# File 'lib/rubyexcel/section.rb', line 203

def length
  @length
end

Instance Method Details

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

Access a Cell by its header

Parameters:

  • header (String)

    the header to search for

Returns:



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

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



240
241
242
243
244
245
246
# File 'lib/rubyexcel/section.rb', line 240

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

#set_value_by_header(header, val) ⇒ Object Also known as: set_val

Set a value in this Row by its header

Parameters:

  • header (String)

    the header to search for

  • val (Object)

    the value to write



275
276
277
# File 'lib/rubyexcel/section.rb', line 275

def set_value_by_header( header, val )
  self[ getref( header ) ] = val
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



263
264
265
# File 'lib/rubyexcel/section.rb', line 263

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