如何使用phpExcel模块以只读模式保存excel文件


How do I save excel file in read-only mode using phpExcel module

我正试图让用户以只读模式保存/下载我的excel文件(apache在windows服务器上,所有下载的用户都使用windows)。

到目前为止,我四处寻找一个好的解决方案,并尝试了所有建议,但似乎都不起作用。

我尝试添加以下行:

$objPHPExcel->getSecurity()->setLockWindows(true);
$objPHPExcel->getSecurity()->setLockStructure(true);

但它仍然以可编辑模式保存。我是不是遗漏了什么?

我更喜欢通过使用phpexcel实现上述目标的解决方案,但使用核心php也是可以接受的。

需要修改phpexcel核心类的东西是不可接受的,因为我们组织中的其他开发人员开发了一大堆应用程序,他们认为核心类是不受影响的。

我没有找到任何没有设置密码的方法。

// Set password for readonly activesheet
$objPHPExcel->getSecurity()->setLockWindows(true);
$objPHPExcel->getSecurity()->setLockStructure(true);
$objPHPExcel->getSecurity()->setWorkbookPassword("password");
// Set password for readonly data
$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
$objPHPExcel->getActiveSheet()->getProtection()->setPassword("password");

来自文档:

文档安全允许您在完整的电子表格上设置密码,只允许在输入密码时进行更改。

他们给出的例子如下:

$objPHPExcel->getSecurity()->setLockWindows(true);
$objPHPExcel->getSecurity()->setLockStructure(true);
$objPHPExcel->getSecurity()->setWorkbookPassword("PHPExcel");

看起来你好像丢了密码。

这段代码从编辑单元格的值和格式化单元格开始就为我工作。

$objPHPExcel->getActiveSheet()->getProtection()->setSort(true);
$objPHPExcel->getActiveSheet()->getProtection()->setInsertRows(true);
$objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true);