Class: Axlsx::ProtectedRanges

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

Overview

A self serializing collection of ranges that should be protected in the worksheet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worksheet) ⇒ ProtectedRanges

Returns a new instance of ProtectedRanges.

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/axlsx/workbook/worksheet/protected_ranges.rb', line 9

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

Instance Attribute Details

#worksheetObject (readonly)

Returns the value of attribute worksheet.



7
8
9
# File 'lib/axlsx/workbook/worksheet/protected_ranges.rb', line 7

def worksheet
  @worksheet
end

Instance Method Details

#add_range(cells) ⇒ Object

Adds a protected range

Parameters:

  • cells (Array|String)

    A string range reference or array of cells that will be protected



17
18
19
20
21
22
23
24
25
# File 'lib/axlsx/workbook/worksheet/protected_ranges.rb', line 17

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

#to_xml_string(str = '') ⇒ Object



27
28
29
30
31
32
# File 'lib/axlsx/workbook/worksheet/protected_ranges.rb', line 27

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