Re: Spreadsheet Excel Writer Password Protect file?
| From: | TAKAGI Masahiro | Date: | Sat, 01 Apr 2006 23:42:16 +0000 |
| Subject: | Re: Spreadsheet Excel Writer Password Protect file? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-23503@lists.php.net to get a copy of this message | ||
Hi,
At Fri, 31 Mar 2006 14:29:17 -0800,
Mark Steudel wrote:
>
> With the spreadsheet_excell package, can you password protect the file? It
> doesn't look like you can, but maybe I missed something.
>
If you mean the password to prevent someone from *opening* the file, you
can't do it by Spreadsheet_Excel_Writer. But we can set the password
to prevent someone from *modifying* the file. To do it, we use
Worksheet::protect with undocumented Format::setLocked.
<?php
require_once 'Spreadsheet/Excel/Writer.php';
$excel = new Spreadsheet_Excel_Writer();
$sheet =& $excel->addWorksheet('mySheet');
$format =& $excel->addFormat();
$format->setLocked(1);
$sheet->protect('yourpasswordhere');
for ($row = 0; $row < 10; $row++) {
for ($col = 0; $col < 10; $col++) {
$sheet->write($row, $col, 'data for (' . $row . ',' . $col .
')', $format);
}
}
$excel->send('result.xls');
$excel->close();
?>
regards,
--
TAKAGI Masahiro mailto:takagi@php.net