DanRz Posted January 24 Share Posted January 24 Hey, I have the following script that looks to make an excel document using PHPSpreadsheet... the script works great, but it doesn't apply the password to the workbook... what am I missing? use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; // Information $arrayData = array('cells'); // Make File Name $filename = 'file-'.time().'.xlsx'; $spreadsheet = new Spreadsheet(); $spreadsheet->getActiveSheet()->getProtection()->setSheet(true); $security = $spreadsheet->getSecurity(); $security->setLockWindows(true); $security->setLockStructure(true); $security->setWorkbookPassword("PhpSpreadsheet"); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('A1', 'Report Generated '. date(DATE_FORMAT_LONG)); $sheet->fromArray($arrayData, NULL, 'A3'); header('Content-Disposition: attachment;filename='.$filename); $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->save('php://output'); Thanks Dan Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.