0

Ok here is the problem. I have the following Code:

$excel = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $excel->load($template);
$objPHPExcel->setActiveSheetIndex(0);
$sheet = $objPHPExcel->getActiveSheet();

//filling up the sheet with tons of info

$sheet->getProtection()->setPassword('YouWishUKnew');
$sheet->getProtection()->setSheet(true);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');

it loads the template stored in $template (duh) and populates it with data.

Here is the problem. The template had some formulas locked, as in the cells weren't even selectable.

After the re-population the lock is gone (so i set it up again, no problem here) but now when I open the re-populated sheet I can see all the formulas!

My question is: Is there a way to lock the cells (make them unselectable) or hide the formulas (like the excel option in Format Cells -> Protection -> Hidden)?

PS: I checked the other questions and didn't find anything to answer my question.

2 Answers 2

3

you should use

$sheet->getStyle('C'.$riga)
      ->getProtection()
      ->setHidden(
          PHPExcel_Style_Protection::PROTECTION_PROTECTED
      );

let me know if this is what you were looking for

Sign up to request clarification or add additional context in comments.

Comments

1

In addition to @Gotrekk answer, in order to make it work, you need to have protection enabled for the active sheet. So, the complete answer would be:

$objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);

$objPHPExcel->getActiveSheet()->getStyle('D3:AS'.$maxRows)
    ->getProtection()
    ->setHidden(PHPExcel_Style_Protection::PROTECTION_PROTECTED);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.