Class: Excel::Row
- Inherits:
-
Object
- Object
- Excel::Row
- Defined in:
- lib/rexcel/row.rb
Overview
A Row in the spreadsheet.
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Array with columns of this row.
-
#style ⇒ Object
readonly
Style for the row.
Instance Method Summary collapse
-
#<<(insertion) ⇒ Object
Add content to the Row.
-
#initialize(options = {}) ⇒ Row
constructor
Define a new row.
-
#inspect ⇒ Object
build_excel_csv.
-
#to_csv(options = {}) ⇒ Object
Build the row for csv.
-
#to_xml(xmlbuilder, ns) ⇒ Object
Build the xml a work sheet row,.
Constructor Details
#initialize(options = {}) ⇒ Row
Define a new row.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rexcel/row.rb', line 9 def initialize( = {}) @log = [:log] || LOGGER @columns = [] .each{|key,value| case key when :log when :style @style = value raise ArgumentError, "Style is no Excel::Style" unless @style.is_a?(Style) else @log.warn("Excel::Row: undefined option #{option}") end } end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Array with columns of this row
24 25 26 |
# File 'lib/rexcel/row.rb', line 24 def columns @columns end |
#style ⇒ Object (readonly)
Style for the row. Is inherited to cells.
26 27 28 |
# File 'lib/rexcel/row.rb', line 26 def style @style end |
Instance Method Details
#<<(insertion) ⇒ Object
Add content to the Row.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rexcel/row.rb', line 30 def << (insertion) case insertion when Cell @columns << insertion when Array insertion.each{|value| @columns << Cell.new(value) } when Hash @log.error("Excel::Row: Hashs not supported") raise ArgumentError, "Excel::Row#<<: Hashs not supported" #fixme: if connectuion to worksheet, use columns. when Row, Worksheet, Workbook raise ArgumentError, "Excel::Row#<<: #{insertion.class} not supported" else @columns << Cell.new(insertion) end self #for usage like " << (Excel::Row.new() << 'a')" end |
#inspect ⇒ Object
build_excel_csv
93 94 95 |
# File 'lib/rexcel/row.rb', line 93 def inspect "#<Excel::Row:#{object_id} #{columns.size} Columns>" end |
#to_csv(options = {}) ⇒ Object
Build the row for csv.
Details on options see Rexcel::Worksheet#to_csv
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rexcel/row.rb', line 76 def to_csv( = {}) @log.debug("Prepare csv-row") #Set options defaults [:sep] ||= ";" csv_row = [] self.columns.each_with_index{|col, colnum| @log.debug("Prepare cell #{colnum} for csv-output") if @log.debug? csv_row << col.to_csv() raise ArgumentError, "Cell separator <#{[:sep]}> is part of the data #{csv_row.last.inspect}" if csv_row.last.to_s.include?([:sep]) }#columns in row csv_row.join([:sep]) end |
#to_xml(xmlbuilder, ns) ⇒ Object
Build the xml a work sheet row,
ns must be a method-object to implement the namespace definitions.
Format options (bold, italic, colors) are forwarded to cells.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rexcel/row.rb', line 56 def to_xml(xmlbuilder, ns) raise EmptyError, "Row without content" if @columns.empty? #Build options = {} if @style [ns.call('StyleID')] = @style.style_id end xmlbuilder[ns.call].Row( ){ @columns.each{|column| column.to_xml(xmlbuilder, ns, self) } } end |