Sha256: 6ef10b4edc9508cc91c3c9dc1d9b299a75bf412416724d5d223d79fecd6f4688

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

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

    # Serializes the protected ranges
    # @param [String] str
    # @return [String]
    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

11 entries across 11 versions & 3 rubygems

Version Path
caxlsx-3.3.0 lib/axlsx/workbook/worksheet/protected_ranges.rb
caxlsx-3.1.1 lib/axlsx/workbook/worksheet/protected_ranges.rb
caxlsx-3.1.0 lib/axlsx/workbook/worksheet/protected_ranges.rb
caxlsx-3.0.4 lib/axlsx/workbook/worksheet/protected_ranges.rb
caxlsx-3.0.3 lib/axlsx/workbook/worksheet/protected_ranges.rb
caxlsx-3.0.2 lib/axlsx/workbook/worksheet/protected_ranges.rb
caxlsx-3.0.1 lib/axlsx/workbook/worksheet/protected_ranges.rb
caxlsx-3.0.0 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-alt-3.0.1 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-alt-3.0.0 lib/axlsx/workbook/worksheet/protected_ranges.rb
axlsx-3.0.0.pre lib/axlsx/workbook/worksheet/protected_ranges.rb