class Rspreadsheet::Border

represents one of the borders of a cell

Public Class Methods

new(cellformat,side) click to toggle source
# File lib/rspreadsheet/cell_format.rb, line 155
def initialize(cellformat,side)
  @cellformat = cellformat
  @side = side.to_s
  raise "Wrong side of border object, can be top, bottom, left or right" unless ['left','right','top','bottom'].include? @side
end

Public Instance Methods

attribute_name() click to toggle source
# File lib/rspreadsheet/cell_format.rb, line 161
def attribute_name; "border-#{@side}" end
cellnode() click to toggle source
# File lib/rspreadsheet/cell_format.rb, line 160
def cellnode; @cell.xmlnode end
color() click to toggle source
# File lib/rspreadsheet/cell_format.rb, line 168
def color; get_border_string_part(3) end
color=(value) click to toggle source
# File lib/rspreadsheet/cell_format.rb, line 165
def color=(value); set_border_string_part(3, value) end
delete() click to toggle source
# File lib/rspreadsheet/cell_format.rb, line 169
def delete
  @cellformat.set_cell_style_node_attribute(attribute_name, 'none')
end
get_border_string() click to toggle source
# File lib/rspreadsheet/cell_format.rb, line 190
def get_border_string
  result = @cellformat.get_cell_style_node_attribute(attribute_name) || @cellformat.get_cell_style_node_attribute('border')
  result = nil if result=='none'
  result
end
get_border_string_part(part) click to toggle source
# File lib/rspreadsheet/cell_format.rb, line 196
def get_border_string_part(part)
  border_string = get_border_string
  return nil if border_string.nil?
    
  value_array = border_string.split(' ')  
  raise 'Strange border attribute value. Does not have 3 parts' unless value_array.length == 3
  return value_array[part-1]
end
set_border_string_part(part,value) click to toggle source

set part-th part of string which represents the border. String looks like “0.06pt solid #00ee00” part is 1 for width, 2 for style or 3 for color

# File lib/rspreadsheet/cell_format.rb, line 177
def set_border_string_part(part,value)
  current_value = @cellformat.get_cell_style_node_attribute(attribute_name)
  
  if current_value.nil? or (current_value=='none')
    value_array = ['0.75pt', 'solid', '#000000']  # set default values
  else
    value_array = current_value.split(' ')  
  end
  raise 'Strange border attribute value. Does not have 3 parts' unless value_array.length == 3
  value_array[part-1]=value
  @cellformat.set_cell_style_node_attribute(attribute_name, value_array.join(' '))
end
style() click to toggle source
# File lib/rspreadsheet/cell_format.rb, line 167
def style; get_border_string_part(2) end
style=(value) click to toggle source
# File lib/rspreadsheet/cell_format.rb, line 164
def style=(value); set_border_string_part(2, value.to_s) end
width() click to toggle source
# File lib/rspreadsheet/cell_format.rb, line 166
def width; get_border_string_part(1).to_f end
width=(value) click to toggle source
# File lib/rspreadsheet/cell_format.rb, line 163
def width=(value); set_border_string_part(1, value) end