Sha256: 568635ba0c0c2801bd0b311e1314803503a2215709190c08113bc08713e35791

Contents?: true

Size: 990 Bytes

Versions: 13

Compression:

Stored size: 990 Bytes

Contents

module Axlsx

  # A self serializing collection of ranges that should be protected in
  # the worksheet
  class ProtectedRanges < SimpleTypedList

    attr_reader :worksheet

    def initialize(worksheet)
      raise ArgumentError, 'You must provide a worksheet' unless worksheet.is_a?(Worksheet)
      super ProtectedRange
      @worksheet = worksheet
    end

    # Adds a protected range
    # @param [Array|String] cells A string range reference or array of cells that will be protected
    def add_range(cells)
     sqref = if cells.is_a?(String)
               cells
             elsif cells.is_a?(SimpleTypedList) || cells.is_a?(Array)
               Axlsx::cell_range(cells, false)
             end
     @list << ProtectedRange.new(:sqref => sqref, :name => "Range#{size}")
     last
    end

    def to_xml_string(str = '')
      return if empty?
      str << '<protectedRanges>'
      each { |range| range.to_xml_string(str) }
      str << '</protectedRanges>' 
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
caxlsx-2.0.2 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-2.0.1 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-2.0.0 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-1.3.6 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-1.3.5 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-1.3.4 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-1.3.3 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-1.3.2 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-1.3.1 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-1.2.3 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-1.2.2 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-1.2.1 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-1.2.0 lib/axlsx/workbook/worksheet/protected_ranges.rb