Sha256: 06e61c4e823ab8e8481b4a71133bf4617c36c591633da73fd4eca5a724bfb9f3

Contents?: true

Size: 989 Bytes

Versions: 6

Compression:

Stored size: 989 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
     self << 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

6 entries across 6 versions & 4 rubygems

Version Path
bonio-axlsx-2.2.3 lib/axlsx/workbook/worksheet/protected_ranges.rb
bonio-axlsx-2.2.2 lib/axlsx/workbook/worksheet/protected_ranges.rb
bonio-axlsx-2.2.1 lib/axlsx/workbook/worksheet/protected_ranges.rb
dg-axlsx-2.1.0 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-2.1.0.pre lib/axlsx/workbook/worksheet/protected_ranges.rb
l_axlsx-2.0.1 lib/axlsx/workbook/worksheet/protected_ranges.rb