Cell protection

Oct 23, 2009 at 2:12 PM

Hello

     I try to protect only one or two cells of my worksheet.

    $ws = $ws = $objPHPExcel->getActiveSheet();    

    //I unlock three cells ( A1, B1, C1 )

    $ws->getStyle('A1')->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
    $ws->getStyle('B1')->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
    $ws->getStyle('C1')->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);

    //I lock two cell

    $ws->protectCells('D1:E1');

    $ws->getProtection()->setSheet(true);

    When I open my worksheet, I can't edit A1, B1, C1.

    How can I do this please ?

    Is possible to unlock a cells area ? For example like that $ws->unProtectCells('A1:C1')

    Thank you

Developer
Oct 23, 2009 at 10:20 PM

>> When I open my worksheet, I can't edit A1, B1, C1.

Strange, I tested your code, and it seemed to work fine. I can edit A1, B1, and C1.

>> Is possible to unlock a cells area ? For example like that $ws->unProtectCells('A1:C1')

Yes, that should be working fine.

Keep in mind that locked/unlocked cells is a different concept than protected/unprotected cells.

It is perhaps easier if you show us the example of what is not working by uploading your Excel file here:

http://phpexcel.codeplex.com/WorkItem/View.aspx?WorkItemId=10749