Method: RubyExcel.borders

Defined in:
lib/rubyexcel/excel_tools.rb

.borders(range, weight = 1, inner = false) ⇒ WIN32OLE::Range

Add borders to an Excel Range

Parameters:

  • range (WIN32OLE::Range)

    the Excel Range to add borders to

  • weight (Fixnum) (defaults to: 1)

    the weight of the borders

  • inner (Boolean) (defaults to: false)

    add inner borders

Returns:

  • (WIN32OLE::Range)

    the range initially given

Raises:

  • (ArgumentError)

    ‘First Argument must be WIN32OLE Range’



19
20
21
22
23
24
25
26
27
28
# File 'lib/rubyexcel/excel_tools.rb', line 19

def self.borders( range, weight=1, inner=false )
  range.ole_respond_to?( :borders ) or fail ArgumentError, 'First Argument must be WIN32OLE Range'
  [0,1,2,3].include?( weight ) or fail ArgumentError, "Invalid line weight #{ weight }. Must be from 0 to 3"
  defined?( ExcelConstants::XlEdgeLeft ) or WIN32OLE.const_load( range.application, ExcelConstants )
  consts = [ ExcelConstants::XlEdgeLeft, ExcelConstants::XlEdgeTop, ExcelConstants::XlEdgeBottom, ExcelConstants::XlEdgeRight, ExcelConstants::XlInsideVertical, ExcelConstants::XlInsideHorizontal ]
  inner or consts.pop(2)
  weight = [ 0, ExcelConstants::XlThin, ExcelConstants::XlMedium, ExcelConstants::XlThick ][ weight ]
  consts.each { |const| weight.zero? ? range.Borders( const ).linestyle = ExcelConstants::XlNone : range.Borders( const ).weight = weight }
  range
end