phpexcel指定列/表(sheet)被锁定受保护加密相应列受保护
一、受保护phpexcel的列
//实例化PHPExcel
$objPhpExcel= new \PHPExcel();
$objPhpExcel->getProperties();
//受保护的地址列
$objPhpExcel->getActiveSheet()->protectCells('A1:A7', 'password');
//解除指定列锁定
$objPhpExcel->getActiveSheet()->getStyle('B1:B7')->getProtection()->setLocked(\PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
//设置sheet锁定属性
$objPhpExcel->getActiveSheet()->getProtection()->setSheet(true);
注:以上方法如果用在指定列缺一不可!具体参数用途参见源代码方法
代码示例
二、phpexcel 受保护的表 sheet
//受保护的sheet
$objPhpExcel->getActiveSheet()->getProtection()->setSheet(true);
$objPhpExcel->getActiveSheet()->getProtection()->setSort(true);
$objPhpExcel->getActiveSheet()->getProtection()->setInsertRows(true);
$objPhpExcel->getActiveSheet()->getProtection()->setFormatCells(true);
$objPhpExcel->getActiveSheet()->getProtection()->setPassword('password');
以上参见:
https://stackoverflow.com/questions/17046207/phpexcel-lock-particular-cell
https://stackoverflow.com/questions/21639731/protect-the-excel-file-using-phpexcel
网友评论