Class: Axlsx::Col
- Inherits:
-
Object
- Object
- Axlsx::Col
- Includes:
- OptionsParser, SerializedAttributes
- Defined in:
- lib/axlsx/workbook/worksheet/col.rb
Overview
The Col class defines column attributes for columns in sheets.
Constant Summary collapse
- MAX_WIDTH =
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
255
Instance Attribute Summary collapse
-
#best_fit ⇒ Boolean
(also: #bestFit)
readonly
Flag indicating if the specified column(s) is set to 'best fit'.
-
#collapsed ⇒ Boolean
Flag indicating if the outlining of the affected column(s) is in the collapsed state.
- #custom_width ⇒ Boolean (also: #customWidth) readonly
-
#hidden ⇒ Boolean
Flag indicating if the affected column(s) are hidden on this worksheet.
-
#max ⇒ Integer
readonly
Last column affected by this 'column info' record.
-
#min ⇒ Integer
readonly
First column affected by this 'column info' record.
-
#outline_level ⇒ Integer
(also: #outlineLevel)
Outline level of affected column(s).
-
#phonetic ⇒ Boolean
Flag indicating if the phonetic information should be displayed by default for the affected column(s) of the worksheet.
-
#style ⇒ Integer
Default style for the affected column(s).
-
#width ⇒ Numeric
The width of the column.
Instance Method Summary collapse
-
#initialize(min, max, options = {}) ⇒ Col
constructor
Create a new Col objects.
-
#to_xml_string(str = +'')) ⇒ String
Serialize this columns data to an xml string.
-
#update_width(cell, fixed_width = nil, use_autowidth = true) ⇒ Object
updates the width for this col based on the cells autowidth and an optionally specified fixed width of the cell should be updated.
Methods included from SerializedAttributes
included, #serialized_attributes, #serialized_element_attributes, #serialized_tag
Methods included from OptionsParser
Constructor Details
#initialize(min, max, options = {}) ⇒ Col
Create a new Col objects
21 22 23 24 25 26 27 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 21 def initialize(min, max, = {}) Axlsx.validate_unsigned_int(max) Axlsx.validate_unsigned_int(min) @min = min @max = max end |
Instance Attribute Details
#best_fit ⇒ Boolean (readonly) Also known as: bestFit
Flag indicating if the specified column(s) is set to 'best fit'. 'Best fit' is set to true under these conditions: The column width has never been manually set by the user, AND The column width is not the default width 'Best fit' means that when numbers are typed into a cell contained in a 'best fit' column, the column width should automatically resize to display the number. [Note: In best fit cases, column width must not be made smaller, only larger. end note]
44 45 46 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 44 def best_fit @best_fit end |
#collapsed ⇒ Boolean
Flag indicating if the outlining of the affected column(s) is in the collapsed state.
49 50 51 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 49 def collapsed @collapsed end |
#custom_width ⇒ Boolean (readonly) Also known as: customWidth
73 74 75 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 73 def custom_width @custom_width end |
#hidden ⇒ Boolean
Flag indicating if the affected column(s) are hidden on this worksheet.
53 54 55 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 53 def hidden @hidden end |
#max ⇒ Integer (readonly)
Last column affected by this 'column info' record.
37 38 39 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 37 def max @max end |
#min ⇒ Integer (readonly)
First column affected by this 'column info' record.
33 34 35 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 33 def min @min end |
#outline_level ⇒ Integer Also known as: outlineLevel
Outline level of affected column(s). Range is 0 to 7.
57 58 59 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 57 def outline_level @outline_level end |
#phonetic ⇒ Boolean
Flag indicating if the phonetic information should be displayed by default for the affected column(s) of the worksheet.
62 63 64 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 62 def phonetic @phonetic end |
#style ⇒ Integer
Default style for the affected column(s). Affects cells not yet allocated in the column(s). In other words, this style applies to new columns.
66 67 68 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 66 def style @style end |
#width ⇒ Numeric
The width of the column
70 71 72 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 70 def width @width end |
Instance Method Details
#to_xml_string(str = +'')) ⇒ String
Serialize this columns data to an xml string
153 154 155 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 153 def to_xml_string(str = +'') serialized_tag('col', str) end |
#update_width(cell, fixed_width = nil, use_autowidth = true) ⇒ Object
updates the width for this col based on the cells autowidth and
an optionally specified fixed width
of the cell should be updated. If this is specified as as Numeric the
width is set to this value and the cell's attributes are ignored. If set
to nil
or :auto
and use_autowidth
is true, it uses the autowidth of
the cell. If set to :ignore
, the cell's width is not changed. In any
case the col's width is set to the new value only if the current width is
smaller than the new one, so that the largest width of all cells in this
column is used.
autowidth value will be ignored.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 134 def update_width(cell, fixed_width = nil, use_autowidth = true) cell_width = case fixed_width when Numeric fixed_width when nil, :auto cell.autowidth if use_autowidth when :ignore nil else raise ArgumentError, "fixed_with must be a Numeric, :auto, :ignore or nil, but is '#{fixed_width.inspect}'" end self.width = cell_width unless (width || 0) > (cell_width || 0) end |