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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionsParser

#parse_options

Methods included from SerializedAttributes

#declared_attributes, 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')

Parameters:

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

    a customizable set of options

Options Hash (options):

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

See Also:

  • Style#add_style


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

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

Instance Attribute Details

#diagonal_downBoolean Also known as: diagonalDown

Returns The diagonal down property for the border that indicates if the border should include a diagonal line from the top left to the top right of the cell.

Returns:

  • (Boolean)

    The diagonal down property for the border that indicates if the border should include a diagonal line from the top left to the top right of the cell.



34
35
36
# File 'lib/axlsx/stylesheet/border.rb', line 34

def diagonal_down
  @diagonal_down
end

#diagonal_upBoolean Also known as: diagonalUp

Returns The diagonal up property for the border that indicates if the border should include a diagonal line from the bottom left to the top right of the cell.

Returns:

  • (Boolean)

    The diagonal up property for the border that indicates if the border should include a diagonal line from the bottom left to the top right of the cell.



30
31
32
# File 'lib/axlsx/stylesheet/border.rb', line 30

def diagonal_up
  @diagonal_up
end

#outlineBoolean

Returns The outline property for the border indicating that top, left, right and bottom borders should only be applied to the outside border of a range of cells.

Returns:

  • (Boolean)

    The outline property for the border indicating that top, left, right and bottom borders should only be applied to the outside border of a range of cells.



38
39
40
# File 'lib/axlsx/stylesheet/border.rb', line 38

def outline
  @outline
end

#prsSimpleTypedList (readonly)

Returns A list of BorderPr objects for this border.

Returns:

  • (SimpleTypedList)

    A list of BorderPr objects for this border.



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

def prs
  @prs
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/axlsx/stylesheet/border.rb', line 57

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