Class: Axlsx::SheetProtection

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

Overview

The SheetProtection object manages worksheet protection options per sheet.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SheetProtection

Creates a new SheetProtection instance

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • sheet (Boolean)

    @see SheetProtection#sheet

  • objects (Boolean)

    @see SheetProtection#objects

  • scenarios (Boolean)

    @see SheetProtection#scenarios

  • format_cells (Boolean)

    @see SheetProtection#objects

  • format_columns (Boolean)

    @see SheetProtection#format_columns

  • format_rows (Boolean)

    @see SheetProtection#format_rows

  • insert_columns (Boolean)

    @see SheetProtection#insert_columns

  • insert_rows (Boolean)

    @see SheetProtection#insert_rows

  • insert_hyperlinks (Boolean)

    @see SheetProtection#insert_hyperlinks

  • delete_columns (Boolean)

    @see SheetProtection#delete_columns

  • delete_rows (Boolean)

    @see SheetProtection#delete_rows

  • select_locked_cells (Boolean)

    @see SheetProtection#select_locked_cells

  • sort (Boolean)

    @see SheetProtection#sort

  • auto_filter (Boolean)

    @see SheetProtection#auto_filter

  • pivot_tables (Boolean)

    @see SheetProtection#pivot_tables

  • select_unlocked_cells (Boolean)

    @see SheetProtection#select_unlocked_cells

  • password. (String)

    The password required for unlocking. @see SheetProtection#password=

  • objects (Boolean)

    @see SheetProtection#objects



131
132
133
134
135
136
137
138
139
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 131

def initialize(options={})
  @objects = @scenarios = @select_locked_cells = @select_unlocked_cells = false
  @sheet = @format_cells = @format_rows = @format_columns = @insert_columns = @insert_rows = @insert_hyperlinks = @delete_columns = @delete_rows = @sort = @auto_filter = @pivot_tables = true
  @password = nil

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

Instance Attribute Details

#auto_filterBoolean (readonly)

If 1 or true then AutoFilters should not be allowed to operate when the sheet is protected. If 0 or false then AutoFilters should be allowed to operate when the sheet is protected. default true

Returns:

  • (Boolean)


11
12
13
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 11

def auto_filter
  @auto_filter
end

#delete_columnsBoolean (readonly)

If 1 or true then deleting columns should not be allowed when the sheet is protected. If 0 or false then deleting columns should be allowed when the sheet is protected. default true

Returns:

  • (Boolean)


17
18
19
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 17

def delete_columns
  @delete_columns
end

#delete_rowsBoolean (readonly)

If 1 or true then deleting rows should not be allowed when the sheet is protected. If 0 or false then deleting rows should be allowed when the sheet is protected. default true

Returns:

  • (Boolean)


23
24
25
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 23

def delete_rows
  @delete_rows
end

#format_cellsBoolean (readonly)

If 1 or true then formatting cells should not be allowed when the sheet is protected. If 0 or false then formatting cells should be allowed when the sheet is protected. default true

Returns:

  • (Boolean)


29
30
31
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 29

def format_cells
  @format_cells
end

#format_columnsBoolean (readonly)

If 1 or true then formatting columns should not be allowed when the sheet is protected. If 0 or false then formatting columns should be allowed when the sheet is protected. default true

Returns:

  • (Boolean)


35
36
37
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 35

def format_columns
  @format_columns
end

#format_rowsBoolean (readonly)

If 1 or true then formatting rows should not be allowed when the sheet is protected. If 0 or false then formatting rows should be allowed when the sheet is protected. default true

Returns:

  • (Boolean)


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

def format_rows
  @format_rows
end

#insert_columnsBoolean (readonly)

If 1 or true then inserting columns should not be allowed when the sheet is protected. If 0 or false then inserting columns should be allowed when the sheet is protected. default true

Returns:

  • (Boolean)


47
48
49
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 47

def insert_columns
  @insert_columns
end

If 1 or true then inserting hyperlinks should not be allowed when the sheet is protected. If 0 or false then inserting hyperlinks should be allowed when the sheet is protected. default true

Returns:

  • (Boolean)


53
54
55
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 53

def insert_hyperlinks
  @insert_hyperlinks
end

#insert_rowsBoolean (readonly)

If 1 or true then inserting rows should not be allowed when the sheet is protected. If 0 or false then inserting rows should be allowed when the sheet is protected. default true

Returns:

  • (Boolean)


59
60
61
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 59

def insert_rows
  @insert_rows
end

#objectsBoolean (readonly)

If 1 or true then editing of objects should not be allowed when the sheet is protected. If 0 or false then objects are allowed to be edited when the sheet is protected. default false

Returns:

  • (Boolean)


65
66
67
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 65

def objects
  @objects
end

#passwordString

Password hash default nil

Returns:

  • (String)


110
111
112
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 110

def password
  @password
end

#pivot_tablesBoolean (readonly)

If 1 or true then PivotTables should not be allowed to operate when the sheet is protected. If 0 or false then PivotTables should be allowed to operate when the sheet is protected. default true

Returns:

  • (Boolean)


71
72
73
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 71

def pivot_tables
  @pivot_tables
end

#salt_valueString (readonly)

Specifies the salt which was prepended to the user-supplied password before it was hashed using the hashing algorithm

Returns:

  • (String)


75
76
77
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 75

def salt_value
  @salt_value
end

#scenariosBoolean (readonly)

If 1 or true then Scenarios should not be edited when the sheet is protected. If 0 or false then Scenarios are allowed to be edited when the sheet is protected. default false

Returns:

  • (Boolean)


81
82
83
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 81

def scenarios
  @scenarios
end

#select_locked_cellsBoolean (readonly)

If 1 or true then selection of locked cells should not be allowed when the sheet is protected. If 0 or false then selection of locked cells should be allowed when the sheet is protected. default false

Returns:

  • (Boolean)


87
88
89
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 87

def select_locked_cells
  @select_locked_cells
end

#select_unlocked_cellsBoolean (readonly)

If 1 or true then selection of unlocked cells should not be allowed when the sheet is protected. If 0 or false then selection of unlocked cells should be allowed when the sheet is protected. default false

Returns:

  • (Boolean)


93
94
95
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 93

def select_unlocked_cells
  @select_unlocked_cells
end

#sheetBoolean (readonly)

If 1 or true then the sheet is protected. If 0 or false then the sheet is not protected. default true

Returns:

  • (Boolean)


99
100
101
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 99

def sheet
  @sheet
end

#sortBoolean (readonly)

If 1 or true then sorting should not be allowed when the sheet is protected. If 0 or false then sorting should be allowed when the sheet is protected. default true

Returns:

  • (Boolean)


105
106
107
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 105

def sort
  @sort
end

Instance Method Details

#f_nameBoolean

create validating setters for boolean values

Returns:

  • (Boolean)


144
145
146
147
148
149
150
151
152
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 144

[:sheet, :objects, :scenarios, :select_locked_cells, :sort,
:select_unlocked_cells, :format_cells, :format_rows, :format_columns,
:insert_columns, :insert_rows, :insert_hyperlinks, :delete_columns,
:delete_rows, :auto_filter, :pivot_tables].each do |f_name|
  define_method "#{f_name.to_s}=".to_sym do |v|
    Axlsx::validate_boolean(v)
    instance_variable_set "@#{f_name.to_s}".to_sym, v
  end
end

#to_xml_string(str = '') ⇒ String

Serialize the object

Parameters:

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

Returns:

  • (String)


181
182
183
184
185
# File 'lib/axlsx/workbook/worksheet/sheet_protection.rb', line 181

def to_xml_string(str = '')
  str << '<sheetProtection '
  str << instance_values.map{ |k,v| k.gsub(/_(.)/){ $1.upcase } << %{="#{v.to_s}"} }.join(' ')
  str << '/>'
end