Search code examples
spreadsheetgear

Issue with using ProtectContent - Spreadsheet gear


I am trying to make a selected cells of my excel to be editable and rest to be readonly.

Following is my code, I am trying to set the Locked property for the specified rows to be "False" and trying to protect the sheet

excl.WorkSheet(0).Range[0, myColumns.Count, rowCount + 2, myColumns.Count].Locked = false; // Unlock cells to not make them read-only by ProtectContents
excl.WorkSheet(0).ProtectContents = true; //Make all the locked cells read only

Say rowCount = 5, I would like to have the entire rows between 0-6 to be editable, but the rest of the fields in the workbook to be read-only.

But, the entire sheet ends up being protected rather than the cells that are locked only. Can anyone please help me fix this


Solution

  • I did this and was able to achieve what I wanted, but I am eager to know any other way to do this as well

      IRange rows = excl.WorkSheet(0).Cells[rowStart, myColumns.Count].EntireRow;
      rows.Locked = false; 
      excl.WorkSheet(0).ProtectContents = true;