This project has moved and is read-only. For the latest updates, please go here.

protect an area

Nov 10, 2011 at 1:53 PM

Like dracolytch I am very happy to have found ClosedXML.

I would like to know how I can protect a worksheet, except for a specific range of cells where the user is allowed to enter data.

I tried xlWorkSheet.Range(UseRange).Release but apparently this doens't work.

Nov 10, 2011 at 3:59 PM

Sorry, I already managed to solve it myself.

Apr 30, 2013 at 2:10 PM
how please explain
May 1, 2013 at 2:05 PM
Edited May 1, 2013 at 2:06 PM
what I have done is the following (the exact syntax might be different for you, depending on the development environment that you are using):
  1. when you create the sheet, release the ranges that you do not want to protect. I used a command like xlWrkshtDotNet.Range(UseRange).Style.Protection.SetLocked(FALSE) for this, where UseRange is a variable, containing the cell, column or row that you do not want to protect. I have used this command every time I had a cell or range that I did not want to protect during the creation process (find that easier than doing it at the end)
  2. at the end of the process of creating the sheet I used xlWrkshtDotNet.Protect(GetPassword) to protect the entire sheet, but the range(s) that I had specified in the first command SETLOCKED(FALSE) will not be protected by this command. I used a function GetPassword to make it possible to dynamically set a document-specific password (it's return variable is a password).
May 1, 2013 at 2:08 PM
great thanks for your help