Class: Axlsx::Xf

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/stylesheet/xf.rb

Overview

The Xf class defines a formatting record for use in Styles. The recommended way to manage styles for your workbook is with Styles#add_style

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Xf

Creates a new Xf object

Parameters:

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

    a customizable set of options

Options Hash (options):

  • numFmtId (Integer)
  • fontId (Integer)
  • fillId (Integer)
  • borderId (Integer)
  • xfId (Integer)
  • quotePrefix (Boolean)
  • pivotButton (Boolean)
  • applyNumberFormat (Boolean)
  • applyFont (Boolean)
  • applyFill (Boolean)
  • applyBorder (Boolean)
  • applyAlignment (Boolean)
  • applyProtection (Boolean)
  • alignment (CellAlignment)
  • protection (CellProtection)


86
87
88
89
90
91
# File 'lib/axlsx/stylesheet/xf.rb', line 86

def initialize(options={})
  options.each do |o|
    next if o[1].nil?
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
end

Instance Attribute Details

#alignmentCellAlignment

The cell alignment for this style

Returns:

See Also:



11
12
13
# File 'lib/axlsx/stylesheet/xf.rb', line 11

def alignment
  @alignment
end

#applyAlignmentBoolean

Indicates if the alignment options should be applied

Returns:

  • (Boolean)


64
65
66
# File 'lib/axlsx/stylesheet/xf.rb', line 64

def applyAlignment
  @applyAlignment
end

#applyBorderBoolean

indicates if the borderId should be applied

Returns:

  • (Boolean)


60
61
62
# File 'lib/axlsx/stylesheet/xf.rb', line 60

def applyBorder
  @applyBorder
end

#applyFillBoolean

indicates if the fillId should be applied

Returns:

  • (Boolean)


56
57
58
# File 'lib/axlsx/stylesheet/xf.rb', line 56

def applyFill
  @applyFill
end

#applyFontBoolean

indicates if the fontId should be applied

Returns:

  • (Boolean)


52
53
54
# File 'lib/axlsx/stylesheet/xf.rb', line 52

def applyFont
  @applyFont
end

#applyNumberFormatBoolean

indicates if the numFmtId should be applied

Returns:

  • (Boolean)


48
49
50
# File 'lib/axlsx/stylesheet/xf.rb', line 48

def applyNumberFormat
  @applyNumberFormat
end

#applyProtectionBoolean

Indicates if the protection options should be applied

Returns:

  • (Boolean)


68
69
70
# File 'lib/axlsx/stylesheet/xf.rb', line 68

def applyProtection
  @applyProtection
end

#borderIdInteger

index (0 based) of the border to be used in this style

Returns:

  • (Integer)


32
33
34
# File 'lib/axlsx/stylesheet/xf.rb', line 32

def borderId
  @borderId
end

#fillIdInteger

index (0 based) of the fill to be used in this style

Returns:

  • (Integer)


28
29
30
# File 'lib/axlsx/stylesheet/xf.rb', line 28

def fillId
  @fillId
end

#fontIdInteger

index (0 based) of the font to be used in this style

Returns:

  • (Integer)


24
25
26
# File 'lib/axlsx/stylesheet/xf.rb', line 24

def fontId
  @fontId
end

#numFmtIdInteger

id of the numFmt to apply to this style

Returns:

  • (Integer)


20
21
22
# File 'lib/axlsx/stylesheet/xf.rb', line 20

def numFmtId
  @numFmtId
end

#pivotButtonBoolean

indicates if the cell has a pivot table drop down button

Returns:

  • (Boolean)


44
45
46
# File 'lib/axlsx/stylesheet/xf.rb', line 44

def pivotButton
  @pivotButton
end

#protectionCellProtection

The cell protection for this style

Returns:

See Also:



16
17
18
# File 'lib/axlsx/stylesheet/xf.rb', line 16

def protection
  @protection
end

#quotePrefixBoolean

indecates if text should be prefixed by a single quote in the cell

Returns:

  • (Boolean)


40
41
42
# File 'lib/axlsx/stylesheet/xf.rb', line 40

def quotePrefix
  @quotePrefix
end

#xfIdInteger

index (0 based) of cellStylesXfs item to be used in this style. Only applies to cellXfs items

Returns:

  • (Integer)


36
37
38
# File 'lib/axlsx/stylesheet/xf.rb', line 36

def xfId
  @xfId
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


133
134
135
136
137
138
139
140
141
# File 'lib/axlsx/stylesheet/xf.rb', line 133

def to_xml_string(str = '')
  str << '<xf '
  h = instance_values.reject { |k, v| [:alignment, :protection, :extList, :name].include? k.to_sym}
  str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
  str << '>'
  alignment.to_xml_string(str) if self.alignment
  protection.to_xml_string(str) if self.protection
  str << '</xf>'
end