class RubyExcel::Row

A Row in the Sheet @attr_reader [Fixnum] idx the Row index @attr_reader [Fixnum] length the Row length

Attributes

idx[R]

The Row number

index[R]

The Row number

Public Class Methods

new( sheet, idx ) click to toggle source

Creates a RubyExcel::Row instance

@param [RubyExcel::Sheet] sheet the Sheet which holds this Row @param [Fixnum] idx the index of this Row

Calls superclass method RubyExcel::Section::new
# File lib/rubyexcel/section.rb, line 228
def initialize( sheet, idx )
  @idx = Integer( idx )
  super( sheet )
end

Public Instance Methods

<<( value ) click to toggle source

Append a value to the Row.

@param [Object] value the object to append @note This only adds an extra cell if it is the first Row

This prevents a loop through Rows from extending diagonally away from the main data.
# File lib/rubyexcel/section.rb, line 241
def <<( value )
  data[ translate_address( idx == 1 ? data.cols + 1 : data.cols ) ] = value
end
cell_by_header( header ) click to toggle source

Access a Cell by its header

@param [String] header the header to search for @return [RubyExcel::Cell] the cell

# File lib/rubyexcel/section.rb, line 252
def cell_by_header( header )
  cell( getref( header ) )
end
Also aliased as: cell_h
cell_h( header )
Alias for: cell_by_header
getref( header ) click to toggle source

Find the Address of a header

@param [String] header the header to search for @return [String] the address of the header

# File lib/rubyexcel/section.rb, line 264
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
length() click to toggle source

The number of Columns in the Row

# File lib/rubyexcel/section.rb, line 276
def length
  data.cols
end
set_val( header, val )
Alias for: set_value_by_header
set_value_by_header( header, val ) click to toggle source

Set a value in this Row by its header

@param [String] header the header to search for @param [Object] val the value to write

# File lib/rubyexcel/section.rb, line 299
def set_value_by_header( header, val )
  self[ getref( header ) ] = val
end
Also aliased as: set_val
val( header )
Alias for: value_by_header
value_by_header( header ) click to toggle source

Find a value in this Row by its header

@param [String] header the header to search for @return [Object] the value at the address

# File lib/rubyexcel/section.rb, line 287
def value_by_header( header )
  self[ getref( header ) ]
end
Also aliased as: val

Private Instance Methods

each_address( unused=nil ) { |translate_address( col_id )| ... } click to toggle source
# File lib/rubyexcel/section.rb, line 306
def each_address( unused=nil )
  return to_enum( :each_address ) unless block_given?
  ( 'A'..col_letter( data.cols ) ).each { |col_id| yield translate_address( col_id ) }
end
translate_address( addr ) click to toggle source
# File lib/rubyexcel/section.rb, line 311
def translate_address( addr )
  col_letter( addr ) + idx.to_s
end