PHPExcel - 锁定正在查看的文件

PHPExcel - locking the file being viewed

我有一份 excel 报告,需要在没有密码验证的情况下锁定以防止查看。我试过以下片段,但它只是让它写保护。以下是我使用的代码片段。

$phpExcelObject->getSecurity()->setLockWindows(true);
$phpExcelObject->getSecurity()->setLockStructure(true);
$phpExcelObject->getSecurity()->setWorkbookPassword("password");

我使用的是 PHPExcel 1.8 版。

这似乎是 PHPExcel 的已知问题

https://github.com/PHPOffice/PHPExcel/issues/442

是否有任何替代库可以用来保护我的报告密码?

谢谢。

PHPExcel 不支持此选项。如果您想锁定文件以供阅读,那么您的选择非常有限。据我所知,唯一能够防止在没有密码的情况下读取文件的库是 PHP 的 COM extension, which requires a COM enabled spreadsheet program such as MS Excel or OpenOffice Calc running on the server; the Open Office alternative to COM (PUNO), which requires Open Office installed on the server with Java support enabled; and Ilia Alshanetsky's Excel extension from github, that requires the commercial libXL component 安装在您的服务器上。