I am in the progress of making a program which needs to generate excel files and have found EPPlus very useful.
I have run into a problem, as I need to protect the sheet, or better yet the entire workbook from changes, but still readable, so I'm not looking for encryption with password so you can't read the workbook, just to lock every cell and sheet from changes.
I have tried with the following code:
package.Workbook.Protection.LockRevision = true;
package.Workbook.Protection.LockStructure = true;
package.Encryption.IsEncrypted = true;
foreach (ExcelWorksheet ws in package.Workbook.Worksheets)
ws.Protection.AllowDeleteColumns = false;
ws.Protection.AllowDeleteRows = false;
ws.Protection.AllowFormatCells = false;
ws.Protection.AllowFormatColumns = false;
ws.Protection.AllowFormatRows = false;
ws.Protection.AllowInsertColumns = false;
ws.Protection.AllowInsertHyperlinks = false;
ws.Protection.AllowInsertRows = false;
ws.Protection.AllowSelectLockedCells = true;
ws.Protection.AllowSort = false;
ws.Protection.IsProtected = true;
ws.Cells[1, 1, 1000, 50].Style.Locked = true;
with mixed success.
It appears to be protected when using e.g. MS Excel 2000, (haven't tried 2007, but would figure it works as well) but when opening the workbook with Open Office 3.2.1 I can change everything and save the workbook again.
Am I missing something?
May 3, 2011 at 9:06 PM
I have done all testing in Excel 2007 and 2010. I haven't looked at protection in Open office, but I know there are a few problems with workbooks generated in EPPlus (graphs, drawings etc)
I'm not sure how hard it will be to fix full open office support (and all other non Excel programs), but that will be something for the future.