Class: Axlsx::Col

Inherits:
Object
  • Object
show all
Includes:
OptionsParser, SerializedAttributes
Defined in:
lib/axlsx/workbook/worksheet/col.rb

Overview

The Col class defines column attributes for columns in sheets.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializedAttributes

#declared_attributes, included, #serialized_attributes, #serialized_element_attributes

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(min, max, options = {}) ⇒ Col

Create a new Col objects

Parameters:

  • min

    First column affected by this 'column info' record.

  • max

    Last column affected by this 'column info' record.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • collapsed (Boolean)

    see Col#collapsed

  • hidden (Boolean)

    see Col#hidden

  • outlineLevel (Boolean)

    see Col#outlineLevel

  • phonetic (Boolean)

    see Col#phonetic

  • style (Integer)

    see Col#style

  • width (Numeric)

    see Col#width



18
19
20
21
22
23
24
# 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

Instance Attribute Details

#best_fitBoolean (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]

Returns:

  • (Boolean)


41
42
43
# File 'lib/axlsx/workbook/worksheet/col.rb', line 41

def best_fit
  @best_fit
end

#collapsedBoolean

Flag indicating if the outlining of the affected column(s) is in the collapsed state.

Returns:

  • (Boolean)


46
47
48
# File 'lib/axlsx/workbook/worksheet/col.rb', line 46

def collapsed
  @collapsed
end

#custom_widthBoolean (readonly) Also known as: customWidth

Returns:

  • (Boolean)


70
71
72
# File 'lib/axlsx/workbook/worksheet/col.rb', line 70

def custom_width
  @custom_width
end

#hiddenBoolean

Flag indicating if the affected column(s) are hidden on this worksheet.

Returns:

  • (Boolean)


50
51
52
# File 'lib/axlsx/workbook/worksheet/col.rb', line 50

def hidden
  @hidden
end

#maxInteger (readonly)

Last column affected by this 'column info' record.

Returns:

  • (Integer)


34
35
36
# File 'lib/axlsx/workbook/worksheet/col.rb', line 34

def max
  @max
end

#minInteger (readonly)

First column affected by this 'column info' record.

Returns:

  • (Integer)


30
31
32
# File 'lib/axlsx/workbook/worksheet/col.rb', line 30

def min
  @min
end

#outline_levelInteger Also known as: outlineLevel

Outline level of affected column(s). Range is 0 to 7.

Returns:

  • (Integer)


54
55
56
# File 'lib/axlsx/workbook/worksheet/col.rb', line 54

def outline_level
  @outline_level
end

#phoneticBoolean

Flag indicating if the phonetic information should be displayed by default for the affected column(s) of the worksheet.

Returns:

  • (Boolean)


59
60
61
# File 'lib/axlsx/workbook/worksheet/col.rb', line 59

def phonetic
  @phonetic
end

#styleInteger

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.

Returns:

  • (Integer)


63
64
65
# File 'lib/axlsx/workbook/worksheet/col.rb', line 63

def style
  @style
end

#widthNumeric

The width of the column

Returns:

  • (Numeric)


67
68
69
# File 'lib/axlsx/workbook/worksheet/col.rb', line 67

def width
  @width
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serialize this columns data to an xml string

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


137
138
139
140
141
# File 'lib/axlsx/workbook/worksheet/col.rb', line 137

def to_xml_string(str = '')
  str << '<col '
  serialized_attributes str
  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 to this value and the cell's attributes are ignored. autowidth value will be ignored.

Parameters:

  • cell (Cell)

    The cell to use in updating this col's width

  • fixed_width (Integer) (defaults to: nil)

    If this is specified the width is set

  • use_autowidth (Boolean) (defaults to: true)

    If this is false, the cell's



124
125
126
127
128
129
130
131
132
# 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)
     #self.width = [width || 0, cell.autowidth || 0].max
   end 
end