Hi,
I am trying make few cells readonly/locking using aspose.cell in Excel format for XLS or XLSX with below code. But when I open the particular file in Excel. It’s protecting complete sheet.
After unprotecting the sheet, I am able to edit the cell in the range of (A14:G20).
Is there any way to protect/lock/make read-only few cells in the worksheet. ( I am using Aspose.Cells.dll of version 7.4.2.3).
public void ReadOnly(Aspose.Cells.Worksheet sheet)
{<span style="color:blue;">for</span> (<span style="color:blue;">int</span> i = 0; i < sheet.Cells.Columns.Count; i++) { Aspose.Cells.<span style="color:#2b91af;">Style</span> style = sheet.Cells.Columns[i].Style; style.IsLocked = <span style="color:blue;">false</span>; <span style="color:blue;">var</span> flag = <span style="color:blue;">new</span> Aspose.Cells.<span style="color:#2b91af;">StyleFlag</span>() { Locked = <span style="color:blue;">true</span> }; sheet.Cells.Columns[i].ApplyStyle(style, flag); } <span style="color:blue;">var</span> range = sheet.Cells.CreateRange(<span style="color:#a31515;">"A14:G20"</span>); <span style="color:#2b91af;">IEnumerator</span> enumerator = range.GetEnumerator(); <span style="color:blue;">while</span> (enumerator.MoveNext()) { <span style="color:blue;">var</span> cell = enumerator.Current <span style="color:blue;">as</span> Aspose.Cells.<span style="color:#2b91af;">Cell</span>; Aspose.Cells.<span style="color:#2b91af;">Style</span> style = cell.GetStyle(); style.IsLocked = <span style="color:blue;">true</span>; <span style="color:green;">//var flag = new Aspose.Cells.StyleFlag() { Locked = true }; </span></pre><pre style="font-family: Consolas; font-size: 13px; background: white;"><span style="color: green;"> </span><span style="color: green;">//cell.SetStyle(style, flag);</span></pre><pre style="font-family: Consolas; font-size: 13px; background: white;"><pre style="font-family: Consolas; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"> cell.SetStyle(style );</pre></pre><pre style="font-family: Consolas; font-size: 13px; background: white;"> } sheet.Protect(<span style="color:#2b91af;">ProtectionType</span>.All); }</pre></div><div><br></div><div>Thanks,</div><div>Ramesh</div>