$excelObj->getActiveSheet()->getProtection()->setPassword('123456');
$excelObj->getActiveSheet()->getProtection()->setSheet(true);
$excelObj->getActiveSheet()->getProtection()->setSort(true);
$excelObj->getActiveSheet()->getProtection()->setInsertRows(true);
$excelObj->getActiveSheet()->getProtection()->setFormatCells(true);在网上找的这种加密的方式,生成的文件还是可以直接打开的做过的大神给个demo
$excelObj->getActiveSheet()->getProtection()->setSheet(true);
$excelObj->getActiveSheet()->getProtection()->setSort(true);
$excelObj->getActiveSheet()->getProtection()->setInsertRows(true);
$excelObj->getActiveSheet()->getProtection()->setFormatCells(true);在网上找的这种加密的方式,生成的文件还是可以直接打开的做过的大神给个demo
4.6.26. Setting security on a spreadsheet
Excel 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.
- Worksheet security offers other security options: you can disallow inserting rows on a specific sheet, disallow sorting, …
- Cell security offers the option to lock/unlock a cell as well as show/hide the internal formulaAn example on setting document security:
$objPHPExcel->getSecurity()->setLockWindows(true);
$objPHPExcel->getSecurity()->setLockStructure(true);
$objPHPExcel->getSecurity()->setWorkbookPassword("PHPExcel");
An example on setting worksheet security:
$objPHPExcel->getActiveSheet()->getProtection()->setPassword('PHPExcel');
$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
$objPHPExcel->getActiveSheet()->getProtection()->setSort(true);
$objPHPExcel->getActiveSheet()->getProtection()->setInsertRows(true);
$objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true);
An example on setting cell security:
$objPHPExcel->getActiveSheet()->getStyle('B1')->getProtection()->setLocked(
PHPExcel_Style_Protection::PROTECTION_UNPROTECTED
);
你可按需要使用其中一种或几种