How to generate a password protected spreadsheet from PHP?

末鹿安然 提交于 2020-01-24 07:21:52

问题


How to generate a password protected spreadsheet from PHP ?

I tried PHPExcel library from http://phpexcel.codeplex.com/

PHPExcel offers 3 levels of “protection”: document security, sheet security and cell security.

Document security allows you to set a password on a complete spreadsheet, allowing changes to be made only when that password is entered. But user can open the spreadsheet and view the contents without password.

And I tried Spreadsheet_Excel_Writer as well, but did not find any solution for this. Spreadsheet_Excel_Writer offers only worksheet level security not the file protection.

Does anyone knows any other PHP Excel writers which offers file protection where users can't even open the Excel file without the password ?


回答1:


Full workbook protection entails encryption of the workbook data, and the encryption algorithm used for this is one facet of the Excel format that I have not seen in any of the available documentation. Certainly none of the PHP Excel writer libraries support this: the only way I know to do it (within the workbook itself) is using the COM extension to build your workbook.




回答2:


You could create the spreadsheet first with PHP and then password protect with the node command-line tool secure-spreadsheet It takes either a csv or xlsx and outputs an encrypted xlsx file.

$infilepath = 'workbook.xlsx';
$outfilepath = 'workbook-encrypted.xlsx';
$encryptionPassword 'password';

$encryptCommand = "cat $infilepath | /usr/local/bin/secure-spreadsheet --password $encryptionPassword --input-format xlsx > $outfilepath ";

exec($encryptCommand);


来源:https://stackoverflow.com/questions/4471904/how-to-generate-a-password-protected-spreadsheet-from-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!