# C1.C1Excel.XLSheet.Locked

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_C1Excel_XLSheet_Locked_" data-uid="C1.C1Excel.XLSheet.Locked*">Locked Property
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_C1Excel_XLSheet_Locked_" data-uid="C1.C1Excel.XLSheet.Locked*"></a>
<h4 id="C1_C1Excel_XLSheet_Locked" data-uid="C1.C1Excel.XLSheet.Locked">Locked</h4>
<div class="markdown level1 summary"><p>Gets or sets a value that determines if the sheet is locked for editing.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public bool Locked { get; set; }</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Property Locked As Boolean</code></pre>
</div>
<h5 id="C1_C1Excel_XLSheet_Locked_remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>Sheets and styles can be locked. By default, sheets are unlocked and styles are locked. 
This combination allows users to edit the cells in Excel.</p>
<p>To protect a cell against editing in Excel, both the sheet and the cell style must have the 
<a class="xref" href="C1.C1Excel.XLSheet.Locked.html#C1_C1Excel_XLSheet_Locked">Locked</a> property set to true.</p>
<p>To lock most cells on a sheet and allow editing of only a few cells, lock the sheet, then 
create an unlocked style and assign it to the cells that should be editable.</p>
</div>
<h5 id="C1_C1Excel_XLSheet_Locked_examples">Examples</h5>
<p>The code below creates a data entry sheet. Most cells are locked, except for the ones where the user
is supposed to enter data.</p>
<pre><code class="lang-csharp">// start with a single locked sheet
_c1xl.Clear();
XLSheet sheet = _c1xl.Sheets[0];
sheet.Locked = true;

// create an unlocked style
XLStyle dataEntry = new XLStyle(_c1xl);
dataEntry.Locked = false;
dataEntry.BackColor = Color.Beige;

// create data entry titles
sheet[0,0].Value = "Name:";
sheet[1,0].Value = "Address:";
sheet[2,0].Value = "Phone #:";

create data entry cells (unlocked)
sheet[0,1].Style = dataEntry;
sheet[1,1].Style = dataEntry;
sheet[2,1].Style = dataEntry;

// save the book
_c1xl.Save(@"c:\temp\Protected.xls");</code></pre>

</div>
