class Axlsx::Col
The Col
class defines column attributes for columns in sheets.
Attributes
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]
@return [Boolean]
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]
@return [Boolean]
Flag indicating if the outlining of the affected column(s) is in the collapsed state. @return [Boolean]
@return [Boolean]
@return [Boolean]
Last column affected by this ‘column info’ record. @return [Integer]
First column affected by this ‘column info’ record. @return [Integer]
Outline level of affected column(s). Range is 0 to 7. @return [Integer]
Outline level of affected column(s). Range is 0 to 7. @return [Integer]
Flag indicating if the phonetic information should be displayed by default for the affected column(s) of the worksheet. @return [Boolean]
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. @return [Integer]
The width of the column @return [Numeric]
Public Class Methods
Create a new Col
objects @param min First column affected by this ‘column info’ record. @param max Last column affected by this ‘column info’ record. @option options [Boolean] collapsed see Col#collapsed
@option options [Boolean] hidden see Col#hidden
@option options [Boolean] outlineLevel see Col#outlineLevel
@option options [Boolean] phonetic see Col#phonetic
@option options [Integer] style see Col#style
@option options [Numeric] width see Col#width
# File lib/axlsx/workbook/worksheet/col.rb, line 18 def initialize(min, max, options={}) Axlsx.validate_unsigned_int(max) Axlsx.validate_unsigned_int(min) @min = min @max = max parse_options options end
Public Instance Methods
@see Col#collapsed
# File lib/axlsx/workbook/worksheet/col.rb, line 74 def collapsed=(v) Axlsx.validate_boolean(v) @collapsed = v end
@see Col#outline
# File lib/axlsx/workbook/worksheet/col.rb, line 86 def outline_level=(v) Axlsx.validate_unsigned_numeric(v) raise ArgumentError, 'outlineLevel must be between 0 and 7' unless 0 <= v && v <= 7 @outline_level = v end
@see Col#phonetic
# File lib/axlsx/workbook/worksheet/col.rb, line 94 def phonetic=(v) Axlsx.validate_boolean(v) @phonetic = v end
@see Col#style
# File lib/axlsx/workbook/worksheet/col.rb, line 100 def style=(v) Axlsx.validate_unsigned_int(v) @style = v end
Serialize this columns data to an xml string @param [String] str @return [String]
# File lib/axlsx/workbook/worksheet/col.rb, line 136 def to_xml_string(str = '') serialized_tag('col', str) 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.
# File lib/axlsx/workbook/worksheet/col.rb, line 124 def update_width(cell, fixed_width=nil, use_autowidth=true) if fixed_width.is_a? Numeric self.width = fixed_width elsif use_autowidth cell_width = cell.autowidth self.width = cell_width unless (width || 0) > (cell_width || 0) end end
@see Col#width
# File lib/axlsx/workbook/worksheet/col.rb, line 106 def width=(v) # Removing this validation make a 10% difference in performance # as it is called EVERY TIME A CELL IS ADDED - the proper solution # is to only set this if a calculated value is greated than the # current @width value. # TODO!!! #Axlsx.validate_unsigned_numeric(v) unless v == nil @custom_width = @best_fit = v != nil @width = v end