Class: Xlsxtream::Row
- Inherits:
-
Object
- Object
- Xlsxtream::Row
- Defined in:
- lib/xlsxtream/row.rb
Instance Method Summary collapse
-
#initialize(row, rownum, sst = nil) ⇒ Row
constructor
A new instance of Row.
- #to_xml ⇒ Object
Constructor Details
#initialize(row, rownum, sst = nil) ⇒ Row
Returns a new instance of Row.
7 8 9 10 11 12 |
# File 'lib/xlsxtream/row.rb', line 7 def initialize(row, rownum, sst = nil) @row = row @rownum = rownum @sst = sst @encoding = Encoding.find("UTF-8") end |
Instance Method Details
#to_xml ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/xlsxtream/row.rb', line 14 def to_xml column = 'A' @row.reduce(%'<row r="#@rownum">') do |xml, value| cid = "#{column}#@rownum" column.next! xml << case value when Numeric %'<c r="#{cid}" t="n"><v>#{value}</v></c>' when Date, Time, DateTime style = value.is_a?(Date) ? 1 : 2 %'<c r="#{cid}" s="#{style}"><v>#{time_to_oa_date value}</v></c>' else value = value.to_s unless value.is_a? String if value.empty? '' else value = value.encode(@encoding) if value.encoding != @encoding if @sst %'<c r="#{cid}" t="s"><v>#{@sst[value]}</v></c>' else %'<c r="#{cid}" t="inlineStr"><is><t>#{XML.escape_value value}</t></is></c>' end end end end << '</row>' end |