class RubyExcel::Row
A Row
in the Sheet
@attr_reader [Fixnum] idx the Row
index @attr_reader [Fixnum] length the Row
length
Attributes
The Row
number
The Row
number
Public Class Methods
Creates a RubyExcel::Row
instance
@param [RubyExcel::Sheet] sheet the Sheet
which holds this Row
@param [Fixnum] idx the index of this Row
RubyExcel::Section::new
# File lib/rubyexcel/section.rb, line 228 def initialize( sheet, idx ) @idx = Integer( idx ) super( sheet ) end
Public Instance Methods
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
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
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
The number of Columns in the Row
# File lib/rubyexcel/section.rb, line 276 def length data.cols end
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
Private Instance Methods
# 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
# File lib/rubyexcel/section.rb, line 311 def translate_address( addr ) col_letter( addr ) + idx.to_s end