Class: RubyXL::Selection

Inherits:
OOXMLObject show all
Defined in:
lib/rubyXL/objects/worksheet.rb

Overview

Instance Method Summary collapse

Methods included from OOXMLObjectClassMethods

#define_attribute, #define_child_node, #define_element_name, #obtain_class_variable, #parse, #set_countable

Methods included from OOXMLObjectInstanceMethods

#dup, #index_in_collection, #initialize, #write_xml

Instance Method Details

#before_write_xmlObject



374
375
376
377
378
379
380
381
382
383
384
# File 'lib/rubyXL/objects/worksheet.rb', line 374

def before_write_xml
  # Normally, rindex of activeCellId in sqref:
  # <selection activeCell="E12" activeCellId="9" sqref="A4 B6 C8 D10 E12 A4 B6 C8 D10 E12"/>
  if @active_cell_id.nil? && !@active_cell.nil? && @sqref.size > 1 then
    # But, things can be more complex:
    # <selection activeCell="E8" activeCellId="2" sqref="A4:B4 C6:D6 E8:F8"/>
    # Not using .reverse.each here to avoid memory reallocation.
    @sqref.each_with_index { |ref, ind| @active_cell_id = ind if ref.cover?(@active_cell) } 
  end
  true
end