Class: RubyExcel::Row
Overview
A Row in the Sheet
Instance Attribute Summary collapse
-
#idx ⇒ Object
(also: #index)
readonly
The Row number.
-
#length ⇒ Object
readonly
The number of Columns in the Row.
Attributes inherited from Section
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Append a value to the Row.
-
#cell_by_header(header) ⇒ RubyExcel::Cell
(also: #cell_h)
Access a Cell by its header.
-
#getref(header) ⇒ String
Find the Address of a header.
-
#initialize(sheet, idx) ⇒ Row
constructor
Creates a RubyExcel::Row instance.
-
#set_value_by_header(header, val) ⇒ Object
(also: #set_val)
Set a value in this Row by its header.
-
#value_by_header(header) ⇒ Object
(also: #val)
Find a value in this Row by its header.
Methods inherited from Section
#cell, #delete, #each, #each_cell, #each_cell_without_headers, #each_without_headers, #empty?, #find, #inspect, #last, #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, #step_index, #to_range_address
Constructor Details
#initialize(sheet, idx) ⇒ Row
Creates a RubyExcel::Row instance
228 229 230 231 |
# File 'lib/rubyexcel/section.rb', line 228 def initialize( sheet, idx ) @idx = Integer( idx ) super( sheet ) end |
Instance Attribute Details
#idx ⇒ Object (readonly) Also known as: index
The Row number
215 216 217 |
# File 'lib/rubyexcel/section.rb', line 215 def idx @idx end |
#length ⇒ Object (readonly)
The number of Columns in the Row
215 216 217 |
# File 'lib/rubyexcel/section.rb', line 215 def length @length end |
Instance Method Details
#<<(value) ⇒ Object
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.
Append a value to the Row.
241 242 243 |
# 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) ⇒ RubyExcel::Cell Also known as: cell_h
Access a Cell by its header
252 253 254 |
# File 'lib/rubyexcel/section.rb', line 252 def cell_by_header( header ) cell( getref( header ) ) end |
#getref(header) ⇒ String
Find the Address of a header
264 265 266 267 268 269 270 |
# 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 |
#set_value_by_header(header, val) ⇒ Object Also known as: set_val
Set a value in this Row by its header
299 300 301 |
# File 'lib/rubyexcel/section.rb', line 299 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
287 288 289 |
# File 'lib/rubyexcel/section.rb', line 287 def value_by_header( header ) self[ getref( header ) ] end |