# spreadsheet-editor-protection

> Spreadsheet editor demonstrating protected worksheets and locked cell editing behavior.

**Framework:** aspnet-mvc  **Component:** Spreadsheet  **Variant:** protection

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/aspnet-mvc/spreadsheet-editor-protection.json
```

**Install Package(s)**

```bash
Install-Package Syncfusion.AspNetMvc.Spreadsheet
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/spreadsheet-editor-protection/SpreadsheetEditor.cshtml

```cshtml
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Spreadsheet

@section ControlsSection{
    <div class="control-section">
        @Html.EJS().Spreadsheet("spreadsheet").Password("spreadsheet").OpenUrl("ProtectSheetOpen").SaveUrl("ProtectSheetSave").Created("createdHandler").BeforeCellRender("beforeCellRenderHandler").Sheets(sheet =>
   {
       sheet.Name("EMI Calculator").IsProtected(true).Rows(row =>
       {
           row.Cells(cell => cell.Index(1).Value("Home Loan Calculator").Style(style =>
           {
               style.FontWeight(FontWeight.Bold).TextAlign(TextAlign.Center);
           }).Add()).Add();
           row.Cells(cell =>
                {
               cell.Index(1).Value("Loan Amount:").Add();
               cell.Format("$#,##0.00").Value("100000").Add();
           }).Add();
           row.Cells(cell =>
                {
               cell.Index(1).Value("Interest Rate:").Add();
               cell.Format("0.00%").Value("0.08").Add();
           }).Add();
           row.Cells(cell =>
                {
               cell.Index(1).Value("Periods (terms in year):").Add();
               cell.Value("1").Add();
           }).Add();
           row.Cells(cell =>
                {
               cell.Index(1).Value("Start Date:").Add();
               cell.Value("03-03-2020").Add();
           }).Add();
           row.Cells(cell =>
                {
               cell.Index(1).Value("Loan EMI:").Add();
               cell.Format("$#,##0.00").Value("8698.84").Add();
           }).Add();
           row.Cells(cell =>
                {
               cell.Index(1).Value("Number of Payments:").Add();
               cell.Value("12").Add();
           }).Add();
           row.Cells(cell =>
                {
               cell.Index(1).Value("Total Repayment Amount:").Add();
               cell.Format("$#,##0.00").Value("104386.11").Add();
           }).Add();
           row.Cells(cell =>
                {
               cell.Index(1).Value("Total Interest  Amount:").Add();
               cell.Format("$#,##0.00").Value("4386.11").Add();
           }).Add();
       }).Columns(column =>
       {
           column.Index(1).Width(190).Add();
           column.Width(100).Add();
       }).Add();
       sheet.IsProtected(true).Name("EMI Schedule").Ranges(ranges =>
            {
           ranges.DataSource(ViewData["ProtectSheetData"]).ShowFieldAsHeader(true).Add();
           }).Rows(row =>
               {
                   row.Cells(cell =>
                   {
                       cell.Style(style => { style.FontWeight(FontWeight.Bold).TextAlign(TextAlign.Center); }).Add();
                       cell.Style(style => { style.FontWeight(FontWeight.Bold).TextAlign(TextAlign.Center); }).Add();
                       cell.Style(style => { style.FontWeight(FontWeight.Bold).TextAlign(TextAlign.Center); }).Add();
                       cell.Style(style => { style.FontWeight(FontWeight.Bold).TextAlign(TextAlign.Center); }).Add();
                       cell.Style(style => { style.FontWeight(FontWeight.Bold).TextAlign(TextAlign.Center); }).Add();
                       cell.Style(style => { style.FontWeight(FontWeight.Bold).TextAlign(TextAlign.Center); }).Add();
                   }).Add();
                }).Columns(column =>
            {
           column.Index(1).Width(110).Add();
           column.Width(85).Add();
           column.Width(85).Add();
           column.Width(80).Add();
           column.Width(90).Add();
       }).Add();
   }).Render()
    </div>
}

<script>
    var numberFormat = ej.spreadsheet.getFormatFromType('Currency');
    function createdHandler() {
        //Applied number formatting to a range
        this.numberFormat("$#,##0.00", 'EMI Schedule!C2:F13');
        this.numberFormat('m/d/yyyy', 'EMI Calculator!C5:C5');
        this.numberFormat('m/d/yyyy', 'EMI Schedule!B2:B13');
    }
    function beforeCellRenderHandler(args) {
        //Merged cells using custom code
        if (this.activeSheetIndex === 0 && args.address === 'B1') {
            args.element.colSpan = 2;
        }
    }
</script>

@*custom code start*@

<style>
    .control-section {
        height: 550px;
    }

    #sb-content .e-spreadsheet .e-tab .e-tab-text {
        display: inherit;
    }
</style>

```

### src/components/spreadsheet-editor-protection/SpreadsheetEditorController.cs

```cs
using Syncfusion.EJ2.Spreadsheet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EJ2MVCSampleBrowser.Controllers.Spreadsheet
{
    public partial class SpreadsheetController : Controller
    {
        // GET: ProtectSheet
        public ActionResult ProtectSheet()
        {
            List<object> data = new List<object>()
            {
                new { Tenure= "1",  PaymentDate= "03-04-2020",  EMI= "8698.84",  Prinicpal= "8032.18",  Interest= "666.67",  Balance= "91967.82" },
                new { Tenure= "2",  PaymentDate= "03-05-2020",  EMI= "8698.84",  Prinicpal= "8085.72",  Interest= "616.12",  Balance= "83882.10" },
                new { Tenure= "3",  PaymentDate= "03-06-2020",  EMI= "8698.84",  Prinicpal= "8139.63",  Interest= "559.21",  Balance= "75742.47" },
            };
            ViewData["ProtectSheetData"] = data;
            return View("~/Views/Home/spreadsheet-editor/protection/SpreadsheetEditor.cshtml");
        }

        public ActionResult ProtectSheetOpen(OpenRequest openRequest)
        {
            return Content(Workbook.Open(openRequest));
        }

        public void ProtectSheetSave(SaveSettings saveSettings)
        {
            if (saveSettings != null && saveSettings.JSONData != null)
            {
                Workbook.Save(saveSettings);
            }
        }
    }
}
```
