PHPExcelWriter2007 and locked cells...

Topics: Developer Forum
Jan 23, 2013 at 8:16 AM

Hi all,

I'm sorry for my google english ;o)

I spent much time with creating a little program but now I do not know what to do.

The users have to download an Excel file, edit it and finally upload it to my app. For my laziness I will not allow users to change the order of columns. Therefore I protect the sheet with a password. So far so good.

But now the users can't insert new lines because all cells are locked by default.

I tried to create a template excel file. In this file I unlocked all cells, load it in my app, fill data - But again, all cells locked!

At the alternate excel framework (PEAR - ExcelSpreadsheetWriter) this problem does not appear, but it can't read and write version 2007.

Now my question: how can I set ALL cells unlocked initially?

Regards Christian

Jan 26, 2013 at 3:54 PM
To my knowledge, PHPExcel don't knows the "ctrl-A" so you have to indicate a range of cells to unlock:

$F->getStyle('A1:A3')->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
(Where $F is the worksheet object).
If you have only defined a password, I advise you to take a close look at different permissions, PHPExcel allowing almost everything by default, unlike Excel.
The Excel display is however misleading. For example, if you allowed the insertion of rows, you can see that "Insert" is grey on the shortcut menu, in the ribbon the main button"insert" is also grayed, but not the submenu where "insert lines" will be available.