diff options
| author | Sergey Ponomarev <[email protected]> | 2020-07-14 10:37:28 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-07-14 16:37:28 +0200 |
| commit | 515177c03121b2ebb5920fd9b673d7da1ebe028d (patch) | |
| tree | ef4bd6d438259d186d38c681e7f823eceaa04755 /lib/axlsx/workbook/worksheet/col.rb | |
| parent | 6639f3cd5d1f64c2e947bd4f39a62d2d1d21bd7b (diff) | |
| download | caxlsx-515177c03121b2ebb5920fd9b673d7da1ebe028d.tar.gz caxlsx-515177c03121b2ebb5920fd9b673d7da1ebe028d.zip | |
Set column width to the maximum allowed value (#53)
Maximum column width limit in MS Excel is 255 characters https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
If this value is exceeded, MS Excel gets stuck and doesn't allow column resizing.
Diffstat (limited to 'lib/axlsx/workbook/worksheet/col.rb')
| -rw-r--r-- | lib/axlsx/workbook/worksheet/col.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/axlsx/workbook/worksheet/col.rb b/lib/axlsx/workbook/worksheet/col.rb index 01086ac3..95204028 100644 --- a/lib/axlsx/workbook/worksheet/col.rb +++ b/lib/axlsx/workbook/worksheet/col.rb @@ -4,6 +4,10 @@ module Axlsx # The Col class defines column attributes for columns in sheets. class Col + # Maximum column width limit in MS Excel is 255 characters + # https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3 + MAX_WIDTH = 255 + include Axlsx::OptionsParser include Axlsx::SerializedAttributes # Create a new Col objects @@ -111,10 +115,10 @@ module Axlsx # TODO!!! #Axlsx.validate_unsigned_numeric(v) unless v == nil @custom_width = @best_fit = v != nil - @width = v + @width = v.nil? ? v : [v, MAX_WIDTH].min end - # updates the width for this col based on the cells autowidth and + # 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 @@ -127,8 +131,8 @@ module Axlsx elsif use_autowidth cell_width = cell.autowidth self.width = cell_width unless (width || 0) > (cell_width || 0) - end - end + end + end # Serialize this columns data to an xml string # @param [String] str |
