I’m trying to password protect excel file
use PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetWriterXlsx;
$spreadsheet = new Spreadsheet();
$activeWorksheet = $spreadsheet->getActiveSheet();
$activeWorksheet->setCellValue('A1', 'Hello World !');
$spreadsheet->getSecurity()->setLockWindows(true);
$spreadsheet->getSecurity()->setLockStructure(true);
$spreadsheet->getSecurity()->setWorkbookPassword("123456");
Above code is not protecting the file
I used encrypt method
$test = new Encrypt($nofile = true);
$output = $test->input($binaryData)
->password('111')
->output();
How to get the binary data from phpspreadsheet output?
$writer = new Xlsx($spreadsheet);
$fileName = 'staff_data.xlsx';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="'. urlencode($fileName).'"');
$writer->save('php://output');