title: How to unlock only specific cells from write protected worksheet using excel javascript API
body: <p>I am using office 365 and Excel online (Build 16.0.9403.1875).</p>
  
  <p>and I am creating Microsoft Excel online <a href="https://docs.microsoft.com/en-us/office/dev/add-ins/excel/excel-add-ins-overview" rel="nofollow noreferrer">Add-ins</a>, using <a href="https://docs.microsoft.com/en-us/office/dev/add-ins/excel/excel-add-ins-core-concepts" rel="nofollow noreferrer">Excel javascript API</a>.</p>
  
  <p>I have a requirement like write protection for entire sheet except few cells (Range).</p>
  
  <p>So, I referred <a href="https://dev.office.com/reference/add-ins/excel/formatprotection" rel="nofollow noreferrer">Format protection API</a>, but while debugging, the ‘locked’ property is of no effect in action.</p>
  
  <p>I referred, stack over flow too with this <a href="https://stackoverflow.com/questions/45463578/how-to-lock-only-dedicated-cells-via-excel-javascript-api">link</a></p>
  
  <p>And <a href="https://www.infragistics.com/community/forums/f/ignite-ui-for-javascript/109693/how-to-lock-unlock-excel-cells" rel="nofollow noreferrer">others</a> too</p>
  
  <p>As, I have already tried with the suggestion given by above forum links. </p>
  
  <p>I just expecting reply by working snippet of code.</p>
  
  <p>My code samples are below</p>
  
  <pre><code>  Excel.run(function (ctx) {
    //Worksheet
    var sheet = ctx.workbook.worksheets.getItem("Sheet1");
  
    //Entire Range
    var entireRange = sheet.getRange();
    entireRange.format.protection.locked = false;  
  
    //Specific Range
    var range = sheet.getRange("A1:B5");  
  
    return ctx.sync()
      .then(() =&gt; {
        //Set specific range "locked" status to true.
        range.format.protection.locked = true;
      })
      .then(ctx.sync)
      .then(() =&gt; {
        //Protect Entire sheet
        sheet.protection.protect({
          allowInsertRows: false,
          allowDeleteRows: false
        });
      });
  }).catch(errorHandler);
  </code></pre>
  
  <p>Thanks.</p>