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

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



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

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)


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

def best_fit
  @best_fit
end

#collapsedBoolean

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

Returns:

  • (Boolean)


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

def collapsed
  @collapsed
end

#custom_widthBoolean (readonly) Also known as: customWidth

Returns:

  • (Boolean)


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

def custom_width
  @custom_width
end

#hiddenBoolean

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

Returns:

  • (Boolean)


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

def hidden
  @hidden
end

#maxInteger (readonly)

Last column affected by this 'column info' record.

Returns:

  • (Integer)


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

def max
  @max
end

#minInteger (readonly)

First column affected by this 'column info' record.

Returns:

  • (Integer)


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

def min
  @min
end

#outline_levelInteger Also known as: outlineLevel

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

Returns:

  • (Integer)


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

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)


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

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)


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

def style
  @style
end

#widthNumeric

The width of the column

Returns:

  • (Numeric)


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

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