Module: Writexlsx::Worksheet::Protection

Included in:
Writexlsx::Worksheet
Defined in:
lib/write_xlsx/worksheet/protection.rb

Overview

Protection-related operations extracted from Worksheet to slim the main class.

Instance Method Summary collapse

Instance Method Details

#protect(password = nil, options = {}) ⇒ Object

Set the worksheet protection flags to prevent modification of worksheet objects.



11
12
13
14
15
16
17
18
19
20
# File 'lib/write_xlsx/worksheet/protection.rb', line 11

def protect(password = nil, options = {})
  check_parameter(options, protect_default_settings.keys, 'protect')
  @protect = protect_default_settings.merge(options)

  # Set the password after the user defined values.
  if password && password != ''
    @protect[:password] =
      encode_password(password)
  end
end

#unprotect_range(range, range_name = nil, password = nil) ⇒ Object

Unprotect ranges within a protected worksheet.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/write_xlsx/worksheet/protection.rb', line 25

def unprotect_range(range, range_name = nil, password = nil)
  if range.nil?
    raise "The range must be defined in unprotect_range())\n"
  else
    range = range.gsub("$", "")
    range = range.sub(/^=/, "")
    @num_protected_ranges += 1
  end

  range_name ||= "Range#{@num_protected_ranges}"
  password   &&= encode_password(password)

  @protected_ranges << [range, range_name, password]
end