Class: Axlsx::PatternFill

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

Overview

Note:

The recommended way to manage styles is with Styles#add_style

A PatternFill is the pattern and solid fill styling for a cell.

See Also:

  • Style#add_style

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PatternFill

Creates a new PatternFill Object

Parameters:

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

    a customizable set of options

Options Hash (options):

  • patternType (Symbol)
  • fgColor (Color)
  • bgColor (Color)


45
46
47
48
49
50
# File 'lib/axlsx/stylesheet/pattern_fill.rb', line 45

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

Instance Attribute Details

#bgColorColor

The color to use for the background of the fill when the type is not solid.

Returns:



14
15
16
# File 'lib/axlsx/stylesheet/pattern_fill.rb', line 14

def bgColor
  @bgColor
end

#fgColorColor

The color to use for the the background in solid fills.

Returns:



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

def fgColor
  @fgColor
end

#patternTypeObject

Note:

patternType must be one of :none :solid :mediumGray :darkGray :lightGray :darkHorizontal :darkVertical :darkDown :darkUp :darkGrid :darkTrellis :lightHorizontal :lightVertical :lightDown :lightUp :lightGrid :lightTrellis :gray125 :gray0625

The pattern type to use

See Also:

  • Open XML Part 1 18.18.55


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

def patternType
  @patternType
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/axlsx/stylesheet/pattern_fill.rb', line 61

def to_xml_string(str = '')
  str << '<patternFill patternType="' << patternType.to_s << '">'
  if fgColor.is_a?(Color)
    str << "<fgColor "
    fgColor.instance_values.each do |key, value|
      str << key.to_s << '="' << value.to_s << '" '
    end
    str << "/>"
  end

  if bgColor.is_a?(Color)
    str << "<bgColor "
    bgColor.instance_values.each do |key, value|
      str << key.to_s << '="' << value.to_s << '" '
    end
    str << "/>"
  end
  str << '</patternFill>'
end