From 1476fd8d0d9a04b03dbc8317d0e94ffa6853ca45 Mon Sep 17 00:00:00 2001 From: Randy Morgan Date: Thu, 16 Feb 2012 19:26:33 +0900 Subject: we need to be able to un-fix a column width --- lib/axlsx/workbook/worksheet/worksheet.rb | 2 ++ test/workbook/worksheet/tc_worksheet.rb | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index eb6f55e9..d4bb6516 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -355,6 +355,8 @@ module Axlsx 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?('=')) + # make sure we can turn that fixed with off! + col[:fixed] = nil if width == :auto cell_xf = cellXfs[item.style] font = fonts[cell_xf.fontId || 0] diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index 96ebfbdf..4a358c2c 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -156,10 +156,19 @@ class TestWorksheet < Test::Unit::TestCase 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.merge_cells "A1:C1" @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_fixed_width_to_auto + @ws.add_row ["hey, I'm like really long and stuff so I think you will merge me."] + @ws.merge_cells "A1:C1" + @ws.add_row ["but Im Short!"], :widths=> [14.8] + assert_equal(@ws.send(:auto_width, @ws.auto_fit_data[0]), 14.8) + @ws.add_row ["no, I like auto!"], :widths=>[:auto] + assert_equal(@ws.auto_fit_data[0][:fixed], nil) + 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") -- cgit v1.2.3