blob: b874b2142dc66a3b0ef1c8e847978b57c916ccc2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# encoding: UTF-8
module Axlsx
# CellProtection stores information about locking or hiding cells in spreadsheet.
# @note Using Styles#add_style is the recommended way to manage cell protection.
# @see Styles#add_style
class CellProtection
# specifies locking for cells that have the style containing this protection
# @return [Boolean]
attr_reader :hidden
# specifies if the cells that have the style containing this protection
# @return [Boolean]
attr_reader :locked
# Creates a new CellProtection
# @option options [Boolean] hidden value for hidden protection
# @option options [Boolean] locked value for locked protection
def initialize(options={})
options.each do |o|
self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
end
end
# @see hidden
def hidden=(v) Axlsx::validate_boolean v; @hidden = v end
# @see locked
def locked=(v) Axlsx::validate_boolean v; @locked = v end
def to_xml_string(str = '')
str << '<protection '
str << instance_values.map { |key, value| '' << key.to_s << '="' << value.to_s << '"' }.join(' ')
str << '/>'
end
# Serializes the cell protection
# @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to.
# @return [String]
def to_xml(xml)
xml.protection(self.instance_values)
end
end
end
|