Method: Writeexcel::Format#set_locked
- Defined in:
- lib/writeexcel/format.rb
#set_locked(arg = 1) ⇒ Object
prevent modification of a cells contents.
Default state: Cell locking is on
Default action: Turn locking on
Valid args: 0, 1
This property can be used to prevent modification of a cells contents. Following Excel’s convention, cell locking is turned on by default. However, it only has an effect if the worksheet has been protected, see the worksheet protect() method.
locked = workbook.add_format()
locked.set_locked(1) # A non-op
unlocked = workbook.add_format()
locked.set_locked(0)
# Enable worksheet protection
worksheet.protect()
# This cell cannot be edited.
worksheet.write('A1', '=1+2', locked)
# This cell can be edited.
worksheet.write('A2', '=1+2', unlocked)
Note: This offers weak protection even with a password, see the note in relation to the protect() method.
860 861 862 863 864 865 866 867 868 869 870 |
# File 'lib/writeexcel/format.rb', line 860 def set_locked(arg = 1) begin if arg == 0 then @locked = 0 elsif arg == 1 then @locked = 1 else raise ArgumentError, "\n\n set_locked(#{arg.inspect})\n arg must be 0, 1, or none.\n" " ( 0:OFF, 1 and none:Lock On )\n" end end end |