# spreadsheet-editor-conditional-formatting

> Spreadsheet editor with conditional formatting rules applied to data ranges.

**Framework:** aspnet-mvc  **Component:** Spreadsheet  **Variant:** conditional-formatting

## 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-conditional-formatting.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-conditional-formatting/SpreadsheetEditor.cshtml

```cshtml
@using Syncfusion.EJ2

@section ControlsSection{
    <div class="control-section">
        @Html.EJS().Spreadsheet("spreadsheet").OpenUrl("ConditionalFormattingOpen").SaveUrl("ConditionalFormattingSave").Created("createdHandler").Sheets(sheet =>
   {
	   sheet.Name("Inventory List").Rows(row =>
	   {
		   row.Height(30).Cells(cell =>
		   {
			   cell.Index(1).Value("Inventory List").Add();
		   }).Add();
	   }).Ranges(ranges =>
	   {
		   ranges.DataSource(ViewData["ConditionalFormattingData"]).StartCell("A2").Add();
	   }).Columns(column =>
	   {
		   column.Width(100).Add();
		   column.Width(158).Add();
		   column.Width(72).Add();
		   column.Width(113).Add();
		   column.Width(113).Add();
		   column.Width(77).Add();
		   column.Width(97).Add();
		   column.Width(73).Add();
	   }).Add();
   }).Render()
    </div>
}

<script>
    function createdHandler() {
        var excelObj = this;
		excelObj.merge('A1:H1');
        excelObj.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A2:H2');
        excelObj.cellFormat({ fontWeight: 'bold', textAlign: 'center', verticalAlign: 'middle', fontSize: '13pt' }, 'A1:H1');
		excelObj.numberFormat('$#,##0.00', 'D3:F18');
        excelObj.numberFormat('m/d/yyyy', 'G3:G18');
        excelObj.conditionalFormat({ type: 'BlueDataBar', range: 'D3:D18' });
		excelObj.conditionalFormat({ type: 'GreenDataBar', range: 'E3:E18' });
        excelObj.conditionalFormat({ type: 'ThreeStars', range: 'H3:H18' });
		excelObj.conditionalFormat({ type: 'LessThan', value: '8-8-2019', range: 'G3:G18' });
		excelObj.conditionalFormat({ type: 'GYRColorScale', range: 'C3:C18' });
		excelObj.conditionalFormat({ type: "Top10Items", value: '1', format: { style: { color: '#ffffff', backgroundColor: '#009999',
            fontWeight: 'bold' } }, range: 'F3:F18' });
		excelObj.conditionalFormat({ type: "Bottom10Items", value: '1', format: { style: { color: '#ffffff', backgroundColor: '#c68d53',
            fontWeight: 'bold' } }, range: 'F3:F18' });
    }
</script>

<style>
    .control-section {
        height: 550px;
    }

    #sb-content .e-spreadsheet .e-tab .e-tab-text {
        display: inherit;
    }
</style>

```

### src/components/spreadsheet-editor-conditional-formatting/SpreadsheetEditorController.cs

```cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Spreadsheet;

namespace EJ2MVCSampleBrowser.Controllers.Spreadsheet
{
    public partial class SpreadsheetController : Controller
    {
        public ActionResult ConditionalFormatting()
        {
            List<object> data = new List<object>()
            {
                new { ItemCode="AG940Z",  ItemName="Laser Printer",  Quantity="144",  PurchasePrice="169.50",  SellingPrice="172.00", Profit= "=E3-D3", LastUpdated ="05-25-19",  Rating="4.5" },
                new { ItemCode="BJ120K",  ItemName="Scientific Calculator",  Quantity="116",  PurchasePrice="21.80",  SellingPrice="23.00", Profit= "=E4-D4", LastUpdated="07-28-19",  Rating="4.0" },
                new { ItemCode="BC120M",  ItemName="Wired Keyboard",  Quantity="438",  PurchasePrice="26.80",  SellingPrice="29.00", Profit= "=E5-D5", LastUpdated="03-30-20",  Rating="4.25" },
            };
            ViewData["ConditionalFormattingData"] = data;
            return View("~/Views/Home/spreadsheet-editor/conditional-formatting/SpreadsheetEditor.cshtml");
        }

        public ActionResult ConditionalFormattingOpen(OpenRequest openRequest)
        {
            return Content(Workbook.Open(openRequest));
        }

        public void ConditionalFormattingSave(SaveSettings saveSettings)
        {
            if (saveSettings != null && saveSettings.JSONData != null)
            {
                Workbook.Save(saveSettings);
            }
        }
    }
}
```
