Class: RubyXL::Selection

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

Overview

Instance Method Summary collapse

Methods inherited from OOXMLObject

#add_to_zip, define_attribute, define_child_node, define_element_name, #dup, filepath, #index_in_collection, #initialize, obtain_class_variable, parse, parse_file, set_countable, set_namespaces, #write_xml

Constructor Details

This class inherits a constructor from RubyXL::OOXMLObject

Instance Method Details

#before_write_xmlObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubyXL/objects/sheet_view.rb', line 25

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