This project has moved. For the latest updates, please go here.

proctect/lock specific cells

Apr 30, 2013 at 1:13 PM
Hi,

I cannot seem to be able to figure out how to lock specific cells from any type of editing and ranges of cells.

If someone can give me a small example it would be very appreciated.

Thanks,
Coordinator
Apr 30, 2013 at 1:35 PM
How would you do it in Excel?
Apr 30, 2013 at 2:52 PM
In excel:
Select all cells and make sure they are unlocked.
Select the cells I want to lock and set them to locked.
Select protect (make sure select locked/unlocked cells are both checked)
Save

This allows me to make specific cells read only…
Apr 30, 2013 at 3:08 PM
this is what I got
        XLWorkbook workbook = new XLWorkbook();
        IXLWorksheet ixlWorksheet = workbook.AddWorksheet("lock test");

        //set values
        ixlWorksheet.Row(1).Cell(1).SetValue("P1");
        ixlWorksheet.Row(1).Cell(2).SetValue("P2");
        ixlWorksheet.Row(1).Cell(3).SetValue("P3");
        ixlWorksheet.Row(1).Cell(4).SetValue("P4");
        ixlWorksheet.Row(1).Cell(5).SetValue("P5");
        ixlWorksheet.Row(1).Cell(6).SetValue("6"); 
        
        //protect
        ixlWorksheet.SelectedRanges.Add(ixlWorksheet.Range(1, 1, 1, 5));
        ixlWorksheet.Protect().SetSelectLockedCells(true);
        ixlWorksheet.SelectedRanges.Clear();
this is what I have so far but it locks all cells on the sheet, and cells 1 -> 5 values are not shown
Jan 20, 2015 at 4:07 PM
dice12345 wrote:
Hi,

I cannot seem to be able to figure out how to lock specific cells from any type of editing and ranges of cells.

If someone can give me a small example it would be very appreciated.

Thanks,
Is this possible using ClosedXml? The example given does not accomplish this. How does one lock specific cells without locking the entire sheet?