Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lock specific rows and columns using Excel interop C#

Tags:

c#

excel

I am trying to Lock cell range in excel using C# excel interop services but I am unable to do it with following code

sheet.Range["A1", "A3"].Locked = true;
like image 756
Fayaz M.D Avatar asked Nov 08 '25 04:11

Fayaz M.D


1 Answers

In Excel, you can only effectively lock cells if you lock the worksheet. What you do is:

  1. Mark the cell ranges you don't want to lock as Locked = False
  2. Then protect the sheet using sheet.Protect(UserInterfaceOnly: true).
like image 138
Paul-Jan Avatar answered Nov 11 '25 02:11

Paul-Jan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!