class RubyXL::ColumnRange

Attributes

custom_width[RW]

min and max are column 0-based indices, as opposed to Excel’s 1-based column numbers

max[RW]

min and max are column 0-based indices, as opposed to Excel’s 1-based column numbers

min[RW]

min and max are column 0-based indices, as opposed to Excel’s 1-based column numbers

style_index[RW]

min and max are column 0-based indices, as opposed to Excel’s 1-based column numbers

width[RW]

min and max are column 0-based indices, as opposed to Excel’s 1-based column numbers

Public Class Methods

find(col_index, ranges) click to toggle source
# File lib/rubyXL/objects/column_range.rb, line 65
def self.find(col_index, ranges)
  ranges.find { |range| range.include?(col_index) }
end
ind2ref(ind) click to toggle source
# File lib/rubyXL/objects/column_range.rb, line 75
def self.ind2ref(ind)
  str = ''

  loop do
    x = ind % 26
    str = ('A'.ord + x).chr + str
    ind = (ind / 26).floor - 1
    return str if ind < 0
  end
end
insert_column(col_index, ranges) click to toggle source
# File lib/rubyXL/objects/column_range.rb, line 35
def self.insert_column(col_index, ranges)
  ranges.each { |range| range.insert_column(col_index) }
end
new(attrs = {}) click to toggle source
# File lib/rubyXL/objects/column_range.rb, line 7
def initialize(attrs = {})
  @min            = attrs['min']
  @max            = attrs['max']
  @width          = attrs['width']
  @custom_width   = attrs['customWidth']
  @style_index    = attrs['style']
end
parse(node) click to toggle source
# File lib/rubyXL/objects/column_range.rb, line 15
def self.parse(node)
  range = self.new
  range.min          = RubyXL::Parser.attr_int(node, 'min') - 1
  range.max          = RubyXL::Parser.attr_int(node, 'max') - 1
  range.width        = RubyXL::Parser.attr_float(node, 'width')
  range.custom_width = RubyXL::Parser.attr_int(node, 'customWidth')
  range.style_index  = RubyXL::Parser.attr_int(node, 'style')
  range
end
ref2ind(ref) click to toggle source
# File lib/rubyXL/objects/column_range.rb, line 69
def self.ref2ind(ref)
  col = 0
  ref.each_byte { |chr| col = col * 26 + (chr - 64) }
  col - 1
end
update(col_index, ranges, attrs) click to toggle source

This method is used to change attributes on a column range, which may involve splitting existing column range into multiples.

# File lib/rubyXL/objects/column_range.rb, line 45
def self.update(col_index, ranges, attrs)

  old_range = RubyXL::ColumnRange.find(col_index, ranges)

  if old_range.nil? then
    new_range = RubyXL::ColumnRange.new(attrs.merge({ 'min' => col_index, 'max' => col_index }))
    ranges << new_range
    return new_range
  elsif old_range.min == col_index && 
          old_range.max == col_index then # Single column range, OK to change in place

    old_range.width = attrs['width'] if attrs['width']
    old_range.custom_width = attrs['customWidth'] if attrs['customWidth']
    old_range.style_index = attrs['style'] if attrs['style']
    return old_range
  else
    raise "Range splitting not implemented yet"
  end
end

Public Instance Methods

delete_column(col) click to toggle source
# File lib/rubyXL/objects/column_range.rb, line 25
def delete_column(col)
  self.min -=1 if min >= col
  self.max -=1 if max >= col
end
include?(col_index) click to toggle source
# File lib/rubyXL/objects/column_range.rb, line 39
def include?(col_index)
  (min..max).include?(col_index)
end
insert_column(col) click to toggle source
# File lib/rubyXL/objects/column_range.rb, line 30
def insert_column(col)
  self.min +=1 if min >= col
  self.max +=1 if max >= col - 1
end