3
########################################################################
5
# Example of cell locking and formula hiding in an Excel worksheet via
6
# the Spreadsheet::WriteExcel module.
8
# reverse('�'), August 2001, John McNamara, jmcnamara@cpan.org
12
use Spreadsheet::WriteExcel;
14
my $workbook = Spreadsheet::WriteExcel->new("protection.xls");
15
my $worksheet = $workbook->add_worksheet();
17
# Create some format objects
18
my $locked = $workbook->add_format(locked => 1);
19
my $unlocked = $workbook->add_format(locked => 0);
20
my $hidden = $workbook->add_format(hidden => 1);
23
$worksheet->set_column('A:A', 42);
24
$worksheet->set_selection('B3:B3');
26
# Protect the worksheet
27
$worksheet->protect();
29
# Examples of cell locking and hiding
30
$worksheet->write('A1', 'Cell B1 is locked. It cannot be edited.');
31
$worksheet->write('B1', '=1+2', $locked);
33
$worksheet->write('A2', 'Cell B2 is unlocked. It can be edited.');
34
$worksheet->write('B2', '=1+2', $unlocked);
36
$worksheet->write('A3', "Cell B3 is hidden. The formula isn't visible.");
37
$worksheet->write('B3', '=1+2', $hidden);
39
$worksheet->write('A5', 'Use Menu->Tools->Protection->Unprotect Sheet');
40
$worksheet->write('A6', 'to remove the worksheet protection. ');