diff options
| author | Randy Morgan <[email protected]> | 2012-02-16 18:27:44 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-02-16 18:27:44 +0900 |
| commit | 10a46e9956bb1a09bb3144845af9b35bb47726dc (patch) | |
| tree | ef494a8bd2ca9a3e1b674840fd46dbb6d3ef48dc | |
| parent | fb198aaef459ebad45f8deed84efbb3e92c340ce (diff) | |
| download | caxlsx-10a46e9956bb1a09bb3144845af9b35bb47726dc.tar.gz caxlsx-10a46e9956bb1a09bb3144845af9b35bb47726dc.zip | |
specifying a fixed with should not require exiting the each loop when setting auto_fit_data
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 2 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_worksheet.rb | 12 |
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index f84e9b92..eb6f55e9 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -352,7 +352,7 @@ module Axlsx col = @auto_fit_data[index] ||= {:longest=>"", :sz=>sz, :fixed=>nil} width = widths[index] # set fixed width and skip if numeric width is given - col[:fixed] = width and next if [Integer, Float, Fixnum].include?(width.class) + col[:fixed] = width if [Integer, Float, Fixnum].include?(width.class) # ignore default column widths and formula next if width == :ignore || (item.value.is_a?(String) && item.value.start_with?('=')) diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index f2c0ae9e..96ebfbdf 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -146,7 +146,7 @@ class TestWorksheet < Test::Unit::TestCase def test_set_fixed_width_column @ws.add_row ["mule", "donkey", "horse"], :widths => [20, :ignore, nil] assert(@ws.auto_fit_data.size == 3, "a data item for each column") - assert_equal({:sz=>11, :longest=>"", :fixed=>20 }, @ws.auto_fit_data[0], "adding a row with fixed width updates :fixed attribute") + assert_equal({:sz=>11, :longest=>"mule", :fixed=>20 }, @ws.auto_fit_data[0], "adding a row with fixed width updates :fixed attribute") assert_equal({:sz=>11, :longest=>"", :fixed=>nil}, @ws.auto_fit_data[1], ":ignore does not set any data") assert_equal({:sz=>11, :longest=>"horse", :fixed=>nil}, @ws.auto_fit_data[2], "nil, well really anything else just works as normal") @ws.add_row ["mule", "donkey", "horse"] @@ -154,6 +154,13 @@ class TestWorksheet < Test::Unit::TestCase end + def test_fixed_widths_with_merged_cells + @ws.add_row ["hey, I'm like really long and stuff so I think you will merge me."] + @ws.add_row ["but Im Short!"], :widths=> [14.8] + assert_equal(@ws.send(:auto_width, @ws.auto_fit_data[0]), 14.8) + end + + def test_auto_width assert(@ws.send(:auto_width, {:sz=>11, :longest=>"fisheries"}) > @ws.send(:auto_width, {:sz=>11, :longest=>"fish"}), "longer strings get a longer auto_width at the same font size") @@ -161,6 +168,8 @@ class TestWorksheet < Test::Unit::TestCase assert_equal(@ws.send(:auto_width, {:sz=>11, :longest => "This is a really long string", :fixed=>0.2}), 0.2, "fixed rules!") end + + def test_set_column_width @ws.add_row ["chasing windmills", "penut"] assert_equal(@ws.auto_fit_data[0][:fixed], nil, 'no fixed by default') @@ -171,7 +180,6 @@ class TestWorksheet < Test::Unit::TestCase assert_raise(ArgumentError, 'only accept Integer, Float or Fixnum') { @ws.column_widths 2, 7, "-1" } end - def test_merge_cells assert(@ws.merged_cells.is_a?(Array)) assert_equal(@ws.merged_cells.size, 0) |
