Class: Axlsx::ProtectedRange

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/protected_range.rb

Overview

Note:

the recommended way to manage protected ranges with via Worksheet#protect_range

The Protected Range class represents a set of cells in the worksheet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ ProtectedRange

Initializes a new protected range object

Parameters:

  • [String] (Hash)

    a customizable set of options

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
23
# File 'lib/axlsx/workbook/worksheet/protected_range.rb', line 18

def initialize(options={})
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
  yield self if block_given?
end

Instance Attribute Details

#nameString

The name of the protected range

Returns:

  • (String)


13
14
15
# File 'lib/axlsx/workbook/worksheet/protected_range.rb', line 13

def name
  @name
end

#sqrefString

The reference for the protected range

Returns:

  • (String)


9
10
11
# File 'lib/axlsx/workbook/worksheet/protected_range.rb', line 9

def sqref
  @sqref
end

Instance Method Details

#to_xml_string(str = "") ⇒ Object

serializes the proteted range our output to that object. Use this - it helps limit the number of objects created during serialization

Parameters:

  • str (String) (defaults to: "")

    if this string object is provided we append



41
42
43
44
# File 'lib/axlsx/workbook/worksheet/protected_range.rb', line 41

def to_xml_string(str="")
  attrs = self.instance_values.reject{ |key, value| value == nil }
  str << '<protectedRange ' << attrs.map { |key, value| '' << key << '="' << value.to_s << '"' }.join(' ') << '/>'
end