Class: RubyXL::Selection

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

Overview

Instance Attribute Summary

Attributes included from OOXMLObjectInstanceMethods

#local_namespaces

Instance Method Summary collapse

Methods included from OOXMLObjectInstanceMethods

#==, included, #index_in_collection, #initialize, #write_xml

Instance Method Details

#before_write_xmlObject



379
380
381
382
383
384
385
386
387
388
389
# File 'lib/rubyXL/objects/worksheet.rb', line 379

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 get more complicated:
    # <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