Class: Axlsx::Border

Inherits:
Object
  • Object
show all
Includes:
OptionsParser, SerializedAttributes
Defined in:
lib/axlsx/stylesheet/border.rb

Overview

This class details a border used in Office Open XML spreadsheet styles.

Constant Summary collapse

EDGES =
[:left, :right, :top, :bottom].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionsParser

#parse_options

Methods included from SerializedAttributes

included, #serialized_attributes, #serialized_element_attributes, #serialized_tag

Constructor Details

#initialize(options = {}) ⇒ Border

Note:

The recommended way to manage borders is with Style#add_style

Creates a new Border object

Examples:

  • Making a border
p = Axlsx::Package.new
red_border = p.workbook.styles.add_style :border => { :style => :thin, :color => "FFFF0000" }
ws = p.workbook.add_worksheet
ws.add_row [1,2,3], :style => red_border
p.serialize('red_border.xlsx')

Options Hash (options):

  • diagonal_up (Boolean)
  • diagonal_down (Boolean)
  • outline (Boolean)

See Also:

  • Style#add_style


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

def initialize(options = {})
  @prs = SimpleTypedList.new BorderPr
  parse_options options
end

Instance Attribute Details

#diagonal_downBoolean Also known as: diagonalDown



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

def diagonal_down
  @diagonal_down
end

#diagonal_upBoolean Also known as: diagonalUp



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

def diagonal_up
  @diagonal_up
end

#outlineBoolean



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

def outline
  @outline
end

#prsSimpleTypedList (readonly)



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

def prs
  @prs
end

Instance Method Details

#to_xml_string(str = +'')) ⇒ String

Serializes the object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/axlsx/stylesheet/border.rb', line 68

def to_xml_string(str = +'')
  str << '<border '
  serialized_attributes str
  str << '>'
  # enforces order
  [:start, :end, :left, :right, :top, :bottom, :diagonal, :vertical, :horizontal].each do |k|
    @prs.select { |pr| pr.name == k }.each do |part|
      part.to_xml_string(str)
    end
  end
  str << '</border>'
end