From 4242c992d411125d09519c27e56933c1e6a9ae16 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Wed, 25 Apr 2012 20:30:57 +0900 Subject: bug fix to properly assign style/type data when creating rows and partial style/types arrays --- lib/axlsx/workbook/worksheet/row.rb | 2 ++ test/workbook/worksheet/tc_row.rb | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/axlsx/workbook/worksheet/row.rb b/lib/axlsx/workbook/worksheet/row.rb index 4e5150da..e04784b3 100644 --- a/lib/axlsx/workbook/worksheet/row.rb +++ b/lib/axlsx/workbook/worksheet/row.rb @@ -132,6 +132,8 @@ module Axlsx cell_type = types.is_a?(Array)? types[index] : types options[:type] = cell_type if cell_type Cell.new(self, value, options) + options.delete(:style) + options.delete(:type) end end end diff --git a/test/workbook/worksheet/tc_row.rb b/test/workbook/worksheet/tc_row.rb index a953566e..a6b4c74a 100644 --- a/test/workbook/worksheet/tc_row.rb +++ b/test/workbook/worksheet/tc_row.rb @@ -32,7 +32,7 @@ class TestRow < Test::Unit::TestCase r_s_xml = Nokogiri::XML(row.to_xml_string(0, '')) assert_equal(r_s_xml.xpath(".//row/c").size, 4) end - + def test_nil_cell_r row = @ws.add_row([nil,1,2,nil,4,5,nil]) r_s_xml = Nokogiri::XML(row.to_xml_string(0, '')) @@ -50,8 +50,15 @@ class TestRow < Test::Unit::TestCase end def test_array_to_cells - r = @ws.add_row [1,2,3], :style=>0, :types=>:integer + r = @ws.add_row [1,2,3], :style=>1, :types=>[:integer, :string, :float] assert_equal(r.cells.size, 3) + r.cells.each do |c| + assert_equal(c.style, 1) + end + r = @ws.add_row [1,2,3], :style=>[1] + assert_equal(r.cells.first.style, 1, "only apply style to cells with at the same index of of the style array") + assert_equal(r.cells.last.style, 0, "only apply style to cells with at the same index of of the style array") + end def test_custom_height -- cgit v1.2.3