Class: Axlsx::Col

Inherits:
Object
  • Object
show all
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

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



95
96
97
98
99
100
101
102
103
# File 'lib/axlsx/workbook/worksheet/col.rb', line 95

def initialize(min, max, options={})
  Axlsx.validate_unsigned_int(max)
  Axlsx.validate_unsigned_int(min)
  @min = min
  @max = max
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
end

Instance Attribute Details

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

Returns:

  • (Boolean)


20
21
22
# File 'lib/axlsx/workbook/worksheet/col.rb', line 20

def bestFit
  @bestFit
end

#collapsedBoolean

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

Returns:

  • (Boolean)


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

def collapsed
  @collapsed
end

#customWidthBoolean (readonly)

Returns:

  • (Boolean)


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

def customWidth
  @customWidth
end

#hiddenBoolean

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

Returns:

  • (Boolean)


28
29
30
# File 'lib/axlsx/workbook/worksheet/col.rb', line 28

def hidden
  @hidden
end

#maxInteger (readonly)

Last column affected by this ‘column info’ record.

Returns:

  • (Integer)


13
14
15
# File 'lib/axlsx/workbook/worksheet/col.rb', line 13

def max
  @max
end

#minInteger (readonly)

First column affected by this ‘column info’ record.

Returns:

  • (Integer)


9
10
11
# File 'lib/axlsx/workbook/worksheet/col.rb', line 9

def min
  @min
end

#outlineLevelInteger

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

Returns:

  • (Integer)


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

def outlineLevel
  @outlineLevel
end

#phoneticBoolean

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

Returns:

  • (Boolean)


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

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)


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

def style
  @style
end

#widthNumeric

The width of the column

Returns:

  • (Numeric)


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

Parameters:

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

Returns:

  • (String)


108
109
110
111
# File 'lib/axlsx/workbook/worksheet/col.rb', line 108

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