Class: Axlsx::Border

Inherits:
Object
  • Object
show all
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

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):

  • diagonalUp (Boolean)
  • diagonalDown (Boolean)
  • outline (Boolean)

See Also:

  • Style#add_style


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

def initialize(options={})
  @prs = SimpleTypedList.new BorderPr
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
end

Instance Attribute Details

#diagonalDownBoolean

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.



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

def diagonalDown
  @diagonalDown
end

#diagonalUpBoolean

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.



7
8
9
# File 'lib/axlsx/stylesheet/border.rb', line 7

def diagonalUp
  @diagonalUp
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.



13
14
15
# File 'lib/axlsx/stylesheet/border.rb', line 13

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.



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

def prs
  @prs
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/axlsx/stylesheet/border.rb', line 48

def to_xml_string(str = '')
  str << '<border '
  h = self.instance_values.select{ |k,v| [:diagonalUp, :diagonalDown, :outline].include? k }
  str << h.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
  str << '>'
  [: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