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.

Constant Summary collapse

MAX_WIDTH =
255

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializedAttributes

#declared_attributes, included, #serialized_attributes, #serialized_element_attributes, #serialized_tag

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


22
23
24
25
26
27
28
# File 'lib/axlsx/workbook/worksheet/col.rb', line 22

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)

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

def best_fit
  @best_fit
end

#collapsedBoolean

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

Returns:

  • (Boolean)

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

def collapsed
  @collapsed
end

#custom_widthBoolean (readonly) Also known as: customWidth

Returns:

  • (Boolean)

74
75
76
# File 'lib/axlsx/workbook/worksheet/col.rb', line 74

def custom_width
  @custom_width
end

#hiddenBoolean

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

Returns:

  • (Boolean)

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

def hidden
  @hidden
end

#maxInteger (readonly)

Last column affected by this 'column info' record.

Returns:

  • (Integer)

38
39
40
# File 'lib/axlsx/workbook/worksheet/col.rb', line 38

def max
  @max
end

#minInteger (readonly)

First column affected by this 'column info' record.

Returns:

  • (Integer)

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

def min
  @min
end

#outline_levelInteger Also known as: outlineLevel

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

Returns:

  • (Integer)

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

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)

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

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)

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

def style
  @style
end

#widthNumeric

The width of the column

Returns:

  • (Numeric)

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

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)

140
141
142
# File 'lib/axlsx/workbook/worksheet/col.rb', line 140

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 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


128
129
130
131
132
133
134
135
# File 'lib/axlsx/workbook/worksheet/col.rb', line 128

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