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)


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

def initialize(options={})
  options.each do |o|
    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:



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

def alignment
  @alignment
end

#applyAlignmentBoolean

Indicates if the alignment options should be applied

Returns:

  • (Boolean)


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

def applyAlignment
  @applyAlignment
end

#applyBorderBoolean

indicates if the borderId should be applied

Returns:

  • (Boolean)


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

def applyBorder
  @applyBorder
end

#applyFillBoolean

indicates if the fillId should be applied

Returns:

  • (Boolean)


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

def applyFill
  @applyFill
end

#applyFontBoolean

indicates if the fontId should be applied

Returns:

  • (Boolean)


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

def applyFont
  @applyFont
end

#applyNumberFormatBoolean

indicates if the numFmtId should be applied

Returns:

  • (Boolean)


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

def applyNumberFormat
  @applyNumberFormat
end

#applyProtectionBoolean

Indicates if the protection options should be applied

Returns:

  • (Boolean)


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

def applyProtection
  @applyProtection
end

#borderIdInteger

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

Returns:

  • (Integer)


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

def borderId
  @borderId
end

#fillIdInteger

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

Returns:

  • (Integer)


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

def fillId
  @fillId
end

#fontIdInteger

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

Returns:

  • (Integer)


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

def fontId
  @fontId
end

#numFmtIdInteger

id of the numFmt to apply to this style

Returns:

  • (Integer)


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

def numFmtId
  @numFmtId
end

#pivotButtonBoolean

indicates if the cell has a pivot table drop down button

Returns:

  • (Boolean)


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

def pivotButton
  @pivotButton
end

#protectionCellProtection

The cell protection for this style

Returns:

See Also:



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

def protection
  @protection
end

#quotePrefixBoolean

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

Returns:

  • (Boolean)


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

def quotePrefix
  @quotePrefix
end

#xfIdInteger

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

Returns:

  • (Integer)


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

def xfId
  @xfId
end

Instance Method Details

#to_xml(xml) ⇒ String

Serializes the xf elemen

Parameters:

  • xml (Nokogiri::XML::Builder)

    The document builder instance this objects xml will be added to.

Returns:

  • (String)


131
132
133
134
135
136
# File 'lib/axlsx/stylesheet/xf.rb', line 131

def to_xml(xml)
  xml.xf(self.instance_values.reject { |k, v| [:alignment, :protection, :extList, :name].include? k.to_sym}) {
    alignment.to_xml(xml) if self.alignment
    protection.to_xml(xml) if self.protection
  }
end