Method: RubyXL::WorksheetConvenienceMethods#add_validation_list

Defined in:
lib/rubyXL/convenience_methods/worksheet.rb

#add_validation_list(ref, list_arr) ⇒ Object

[View source]

720
721
722
723
724
725
726
727
728
729
730
# File 'lib/rubyXL/convenience_methods/worksheet.rb', line 720

def add_validation_list(ref, list_arr)
  # "Any double quote characters in the value should be escaped with another double quote.
  # If the value does not contain a comma, newline or double quote, then the String value should be returned unchanged.
  # If the value contains a comma, newline or double quote, then the String value should be returned enclosed in double quotes."
  expr = '"' + list_arr.collect{ |str| str.gsub('"', '""') }.join(',') + '"'
  self.data_validations ||= RubyXL::DataValidations.new
  self.data_validations <<
    RubyXL::DataValidation.new({:sqref    => RubyXL::Reference.new(ref),
                                :formula1 => RubyXL::Formula.new(:expression => expr),
                                :type     => 'list'})
end