How to generate a password protected spreadsheet from PHP?
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 ?
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.
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);
You could create the spreadsheet first with PHP and then password protect with the secure-spreadsheet .It take xlsx and outputs an encrypted xlsx file.
require "vendor/autoload.php";
use Nick\SecureSpreadsheet\Encrypt;
$test = new Encrypt();
$test->input('Book1.xlsx')
->password('111')
->output('bb.xlsx');
精彩评论