summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/col.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-07-15 13:29:18 +0900
committerRandy Morgan <[email protected]>2012-07-15 13:29:18 +0900
commit14beaaac13637f2153faa3b851f3e849974df556 (patch)
tree3fd3f23addb01df172c2eca738220b2d9106f34a /lib/axlsx/workbook/worksheet/col.rb
parent46c67de5cc3d8a1350fc3cf0773b2d56b019f960 (diff)
downloadcaxlsx-14beaaac13637f2153faa3b851f3e849974df556.tar.gz
caxlsx-14beaaac13637f2153faa3b851f3e849974df556.zip
refactoring auto width calculation to improve code quality.
Diffstat (limited to 'lib/axlsx/workbook/worksheet/col.rb')
-rw-r--r--lib/axlsx/workbook/worksheet/col.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/axlsx/workbook/worksheet/col.rb b/lib/axlsx/workbook/worksheet/col.rb
index fb19a1bd..18414b62 100644
--- a/lib/axlsx/workbook/worksheet/col.rb
+++ b/lib/axlsx/workbook/worksheet/col.rb
@@ -102,6 +102,21 @@ module Axlsx
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
end
end
+
+ # updates the width for this col based on the cells autowidth and
+ # an optionally specified fixed width
+ # @param [Cell] cell The cell to use in updating this col's width
+ # @param [Integer] fixed_width If this is specified the width is set
+ # to this value and the cell's attributes are ignored.
+ # @param [Boolean] use_autowidth If this is false, the cell's
+ # autowidth value will be ignored.
+ def update_width(cell, fixed_width=nil, use_autowidth=true)
+ if fixed_width.is_a? Numeric
+ self.width = fixed_width
+ elsif use_autowidth
+ self.width = [width || 0, cell.autowidth || 0].max
+ end
+ end
# Serialize this columns data to an xml string
# @param [String] str