Class: Axlsx::Col
- Inherits:
-
Object
- Object
- Axlsx::Col
- Defined in:
- lib/axlsx/workbook/worksheet/col.rb
Overview
The Col class defines column attributes for columns in sheets.
Instance Attribute Summary collapse
-
#bestFit ⇒ Boolean
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.
- #customWidth ⇒ Boolean 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.
-
#outlineLevel ⇒ Integer
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 to this value and the cell's attributes are ignored.
Constructor Details
#initialize(min, max, options = {}) ⇒ Col
Create a new Col objects
96 97 98 99 100 101 102 103 104 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 96 def initialize(min, max, ={}) Axlsx.validate_unsigned_int(max) Axlsx.validate_unsigned_int(min) @min = min @max = max .each do |o| self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" end end |
Instance Attribute Details
#bestFit ⇒ Boolean (readonly)
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]
20 21 22 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 20 def bestFit @bestFit end |
#collapsed ⇒ Boolean
Flag indicating if the outlining of the affected column(s) is in the collapsed state.
24 25 26 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 24 def collapsed @collapsed end |
#customWidth ⇒ Boolean (readonly)
47 48 49 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 47 def customWidth @customWidth end |
#hidden ⇒ Boolean
Flag indicating if the affected column(s) are hidden on this worksheet.
28 29 30 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 28 def hidden @hidden end |
#max ⇒ Integer (readonly)
Last column affected by this 'column info' record.
13 14 15 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 13 def max @max end |
#min ⇒ Integer (readonly)
First column affected by this 'column info' record.
9 10 11 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 9 def min @min end |
#outlineLevel ⇒ Integer
Outline level of affected column(s). Range is 0 to 7.
32 33 34 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 32 def outlineLevel @outlineLevel end |
#phonetic ⇒ Boolean
Flag indicating if the phonetic information should be displayed by default for the affected column(s) of the worksheet.
36 37 38 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 36 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.
40 41 42 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 40 def style @style end |
#width ⇒ Numeric
The width of the column
44 45 46 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 44 def width @width end |
Instance Method Details
#to_xml_string(str = '') ⇒ String
Serialize this columns data to an xml string
124 125 126 127 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 124 def to_xml_string(str = '') attrs = self.instance_values.reject{ |key, value| value == nil } str << '<col ' << attrs.map { |key, value| '' << key << '="' << value.to_s << '"' }.join(' ') << '/>' 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 to this value and the cell's attributes are ignored. autowidth value will be ignored.
113 114 115 116 117 118 119 |
# File 'lib/axlsx/workbook/worksheet/col.rb', line 113 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 |