enable editing for empty cell

Topics: Developer Forum, User Forum
Aug 2, 2010 at 8:40 PM

Hi, All

I am produce excel using protection. My goal is simple. User can not modify the cell pre-filled with values, but he can edit any cell without a pre-filled value.

I am using this code:

$sheet->getProtection()->setSheet(true)->setDeleteColumns(false)->setDeleteRows(false)->setSort(false)->setInsertRows(false)->setInsertColumns(false);
...

//lock cell with values

$sheet->setCellValue("A1", "Study");
$sheet->getStyle('A1')->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_PROTECTED);

 

//unlock cell without values

$sheet->getStyleByColumnAndRow($i, $j)->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);

//output the excel

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

 

However,  all the cells are protected. End user can not edit any cells.

Any suggestion?