diff options
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 4 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_worksheet.rb | 7 |
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 29bea8d3..11a2292e 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -303,7 +303,7 @@ module Axlsx # ignore formula - there is no way for us to know the result next if item.value.is_a?(String) && item.value.start_with?('=') - col = @auto_fit_data[index] || {:longest=>"", :sz=>sz} + col = @auto_fit_data[index] || {:longest=>"", :sz=>sz, :fixed=>nil} cell_xf = cellXfs[item.style] font = fonts[cell_xf.fontId || 0] sz = item.sz || font.sz || fonts[0].sz @@ -322,6 +322,8 @@ module Axlsx # @return [Float] # @param [Hash] A hash of auto_fit_data def auto_width(col) + return col[:fixed] unless col[:fixed] == nil + mdw_count, font_scale, mdw = 0, col[:sz]/11.0, 6.0 mdw_count = col[:longest].scan(/./mu).reduce(0) do | count, char | count +=1 if @magick_draw.get_type_metrics(char).max_advance >= mdw diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index b7f93d97..3e5bc4c4 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -136,20 +136,21 @@ class TestWorksheet < Test::Unit::TestCase @ws.add_row ["chasing windmills", "penut"], :style=>small assert(@ws.auto_fit_data.size == 2, "a data item for each column") - assert_equal(@ws.auto_fit_data[0], {:sz=>2,:longest=>"chasing windmills"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column") + assert_equal(@ws.auto_fit_data[0], {:sz => 2, :longest => "chasing windmills", :fixed=>nil}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column") @ws.add_row ["mule"], :style=>big - assert_equal(@ws.auto_fit_data[0], {:sz=>10,:longest=>"mule"}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column") + assert_equal(@ws.auto_fit_data[0], {:sz=>10,:longest=>"mule", :fixed=>nil}, "adding a row updates auto_fit_data if the product of the string length and font is greater for the column") 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") assert(@ws.send(:auto_width, {:sz=>11, :longest=>"fish"}) < @ws.send(:auto_width, {:sz=>12, :longest=>"fish"}), "larger fonts produce longer with with same string") - + 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_merge_cells assert(@ws.merged_cells.is_a?(Array)) assert_equal(@ws.merged_cells.size, 0) |
