Search results

Cell Range in ASP.NET Core Spreadsheet control

28 Jul 2021 / 5 minutes to read

A group of cells in a sheet is known as cell range.

Wrap text

Wrap text allows you to display large content as multiple lines in a single cell. By default, the wrap text support is enabled. Use the allowWrap property to enable or disable the wrap text support in spreadsheet.

Wrap text can be applied or removed to a cell or range of cells in the following ways,

  • Using the wrap property in cell, you can enable or disable wrap text to a cell at initial load.
  • Select or deselect wrap button from ribbon toolbar to apply or remove the wrap text to the selected range.
  • Using the wrap method, you can apply or remove the wrap text once the component is loaded.

The following code example shows the wrap text functionality in spreadsheet.

tagHelper
wrapTextController.cs
Copied to clipboard
<ejs-spreadsheet id="spreadsheet" created="created" showFormulaBar="false">
        <e-spreadsheet-sheets>
            <e-spreadsheet-sheet selectedRange="C7" >
                <e-spreadsheet-ranges>
                    <e-spreadsheet-range dataSource="ViewBag.DefaultData"></e-spreadsheet-range>
                </e-spreadsheet-ranges>
                <e-spreadsheet-rows>
                    <e-spreadsheet-row height="30"></e-spreadsheet-row>
                    <e-spreadsheet-row>
                        <e-spreadsheet-cells>
                            <e-spreadsheet-cell index="7" wrap="true"></e-spreadsheet-cell>
                        </e-spreadsheet-cells>
                    </e-spreadsheet-row>
                    <e-spreadsheet-row>
                        <e-spreadsheet-cells>
                            <e-spreadsheet-cell index="7" wrap="true"></e-spreadsheet-cell>
                        </e-spreadsheet-cells>
                    </e-spreadsheet-row>
                    <e-spreadsheet-row>
                        <e-spreadsheet-cells>
                            <e-spreadsheet-cell index="7" wrap="true"></e-spreadsheet-cell>
                        </e-spreadsheet-cells>
                    </e-spreadsheet-row>
                    <e-spreadsheet-row>
                        <e-spreadsheet-cells>
                            <e-spreadsheet-cell index="7" wrap="true"></e-spreadsheet-cell>
                        </e-spreadsheet-cells>
                    </e-spreadsheet-row>
                </e-spreadsheet-rows>
                <e-spreadsheet-columns>
                    <e-spreadsheet-column index="1" width="100"></e-spreadsheet-column>
                    <e-spreadsheet-column width="140"></e-spreadsheet-column>
                    <e-spreadsheet-column width="90"></e-spreadsheet-column>
                    <e-spreadsheet-column width="150"></e-spreadsheet-column>
                    <e-spreadsheet-column width="120"></e-spreadsheet-column>
                    <e-spreadsheet-column width="90"></e-spreadsheet-column>
                    <e-spreadsheet-column width="180"></e-spreadsheet-column>
                </e-spreadsheet-columns>
            </e-spreadsheet-sheet>
        </e-spreadsheet-sheets>
    </ejs-spreadsheet>


    <script>

    function created() {
        this.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:H1');
        this.cellFormat({ verticalAlign: 'middle' }, 'A1:H5');
        this.cellFormat({ textAlign: 'center' }, 'A2:B5');
        this.cellFormat({ textAlign: 'center' }, 'D2:D5');
        // To wrap the cells from E2 to E5 range
        this.wrap('E2:E5');
        // To unwrap the H3 cell
        this.wrap('H3', false);
    }
    </script>
Copied to clipboard
public IActionResult Index()
        {
            List<object> data = new List<object>()
            {
                new { No= "1",  ReleasedOn= "1994",  Title= "Forrest Gump",  Rating= "5 Stars",  Casts= "Tom Hanks, Robin Wright, Gary Sinise",  DirectedBy= "Robert Zemeckis", Genre= "Drama", Comments= "Based on the 1986 novel of the same name by Winston Groom" },
                new { No= "2",  ReleasedOn= "1946",  Title= "It’s a Wonderful Life",  Rating= "2 Stars",  Casts= "James Stewart, Donna Reed, Lionel Barrymore",  DirectedBy= "Frank Capra", Genre= "Drama", Comments= "Colorized version"  },
                new { No= "3",  ReleasedOn= "1988",  Title= "Big",  Rating= "4 Stars",  Casts= "Tom Hanks, Elizabeth Perkins, Robert Loggia",  DirectedBy= "Penny Marshall", Genre= "Comedy", Comments= "A thirteen-year-old boy wishes to be big, and his wish comes true."  },
                new { No= "4",  ReleasedOn= "1954",  Title= "Rear Window",  Rating= "4 Stars",  Casts= "James Stewart, Grace Kelly, Wendell Corey",  DirectedBy= "Alfred Hitchcock" , Genre= "Suspense", Comments= "Truly suspenseful and masterfully crafted" },
            };
            ViewBag.DefaultData = data;
            return View();
        }

Limitations of Wrap text

The following features have some limitations in wrap text:

  • Sorting with wrap text applied data.
  • Merge with wrap text

Merge cells

Merge cells allows users to span two or more cells in the same row or column into a single cell. When cells with multiple values are merged, top-left most cell data will be the data for the merged cell. By default, the merge cells option is enabled. Use allowMerge property to enable or disable the merge cells option in spreadsheet.

You can merge the range of cells in the following ways,

  • Set the rowSpan and colSpan property in cell to merge the number of cells at initial load.
  • Select the range of cells and apply merge by selecting the desired option from ribbon toolbar.
  • Use merge method to merge the range of cells, once the component is loaded.

The available merge options in spreadsheet are,

Type Action
Merge All Combines all the cells in a range in to a single cell (default).
Merge Horizontally Combines cells in a range as row-wise.
Merge Vertically Combines cells in a range as column-wise.
UnMerge Splits the merged cells into multiple cells.

The following code example shows the merge cells operation in spreadsheet.

tagHelper
mergeCellController.cs
Copied to clipboard
<ejs-spreadsheet id="spreadsheet" created="created" showFormulaBar="false">
        <e-spreadsheet-sheets>
            <e-spreadsheet-sheet name="Merge Cells" >
                <e-spreadsheet-ranges>
                    <e-spreadsheet-range dataSource="ViewBag.DefaultData"></e-spreadsheet-range>
                </e-spreadsheet-ranges>
                <e-spreadsheet-rows>
                    <e-spreadsheet-row height="35"></e-spreadsheet-row>
                    <e-spreadsheet-row height="35">
                        <e-spreadsheet-cells>
                            <e-spreadsheet-cell index="1" rowSpan="2"></e-spreadsheet-cell>
                            <e-spreadsheet-cell colSpan="2"></e-spreadsheet-cell>
                            <e-spreadsheet-cell index="6" colSpan="3"></e-spreadsheet-cell>
                            <e-spreadsheet-cell index="10" rowSpan="2" colSpan="3"></e-spreadsheet-cell>
                            <e-spreadsheet-cell index="13" colSpan="2"></e-spreadsheet-cell>
                            <e-spreadsheet-cell index="17" colSpan="2"></e-spreadsheet-cell>
                        </e-spreadsheet-cells>
                    </e-spreadsheet-row>
                    <e-spreadsheet-row height="35">
                        <e-spreadsheet-cells>
                            <e-spreadsheet-cell index="3" colSpan="3"></e-spreadsheet-cell>
                            <e-spreadsheet-cell colSpan="4" index="6"></e-spreadsheet-cell>
                            <e-spreadsheet-cell index="13" colSpan="3"></e-spreadsheet-cell>
                            <e-spreadsheet-cell index="17" colSpan="2"></e-spreadsheet-cell>
                        </e-spreadsheet-cells>
                    </e-spreadsheet-row>
                    <e-spreadsheet-row height="35">
                        <e-spreadsheet-cells>
                            <e-spreadsheet-cell index="2" colSpan="3"></e-spreadsheet-cell>
                            <e-spreadsheet-cell colSpan="2" index="5"></e-spreadsheet-cell>
                            <e-spreadsheet-cell index="7" colSpan="3"></e-spreadsheet-cell>
                            <e-spreadsheet-cell index="15" colSpan="2"></e-spreadsheet-cell>
                        </e-spreadsheet-cells>
                    </e-spreadsheet-row>
                    <e-spreadsheet-row height="35">
                        <e-spreadsheet-cells>
                            <e-spreadsheet-cell index="2" colSpan="3"></e-spreadsheet-cell>
                            <e-spreadsheet-cell colSpan="4" index="6"></e-spreadsheet-cell>
                            <e-spreadsheet-cell index="16" colSpan="2"></e-spreadsheet-cell>
                        </e-spreadsheet-cells>
                    </e-spreadsheet-row>
                    <e-spreadsheet-row height="35">
                        <e-spreadsheet-cells>
                            <e-spreadsheet-cell index="2" colSpan="4"></e-spreadsheet-cell>
                            <e-spreadsheet-cell colSpan="3" index="7"></e-spreadsheet-cell>
                            <e-spreadsheet-cell index="15" colSpan="2"></e-spreadsheet-cell>
                            <e-spreadsheet-cell index="17" colSpan="2"></e-spreadsheet-cell>
                        </e-spreadsheet-cells>
                    </e-spreadsheet-row>
                </e-spreadsheet-rows>
                <e-spreadsheet-columns>
                    <e-spreadsheet-column width="90"></e-spreadsheet-column>
                    <e-spreadsheet-column width="150"></e-spreadsheet-column>
                    <e-spreadsheet-column width="100"></e-spreadsheet-column>
                    <e-spreadsheet-column width="100"></e-spreadsheet-column>
                    <e-spreadsheet-column width="100"></e-spreadsheet-column>
                    <e-spreadsheet-column width="100"></e-spreadsheet-column>
                    <e-spreadsheet-column width="100"></e-spreadsheet-column>
                    <e-spreadsheet-column width="100"></e-spreadsheet-column>
                    <e-spreadsheet-column width="100"></e-spreadsheet-column>
                    <e-spreadsheet-column width="100"></e-spreadsheet-column>
                    <e-spreadsheet-column width="120"></e-spreadsheet-column>
                    <e-spreadsheet-column width="120"></e-spreadsheet-column>
                    <e-spreadsheet-column width="120"></e-spreadsheet-column>
                    <e-spreadsheet-column width="120"></e-spreadsheet-column>
                    <e-spreadsheet-column width="120"></e-spreadsheet-column>
                    <e-spreadsheet-column width="120"></e-spreadsheet-column>
                    <e-spreadsheet-column width="100"></e-spreadsheet-column>
                    <e-spreadsheet-column width="100"></e-spreadsheet-column>
                    <e-spreadsheet-column width="100"></e-spreadsheet-column>
                    <e-spreadsheet-column width="100"></e-spreadsheet-column>
                </e-spreadsheet-columns>
            </e-spreadsheet-sheet>
        </e-spreadsheet-sheets>
    </ejs-spreadsheet>


    <script>

      function created() {
       this.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:S1');
        this.numberFormat('h:mm AM/PM', 'C1:S1');
        this.cellFormat({ verticalAlign: 'middle' }, 'A1:S11');
        // Merging the `K4:M4` cells using method
        this.merge('K4:M4');
        // Merging the 5th and 6th row cells across 11th, 12th and 13th column
        this.merge('K5:M6', 'Vertically');
        // Merging the 18th and 19th column cells across 2nd, 3rd and 4th row
        this.merge('N4:O6', 'Horizontally');
    }
    </script>
Copied to clipboard
public IActionResult Index()
        {
            List<object> data = new List<object>()
            {
                new { EmployeeID= "10001",  EmployeeName= "Davolio",  NineAM= "Analysis Task",  NinethirtyAM= "Analysis Task",  TenAM= "Team Meeting",  TenthirtyAM= "Testing", ElevenAM= "Development",  EleventhirtyAM= "Development",  TwelvePM= "Development",  TwelvethirtyPM= "Support", OnePM= "Lunch Break",  OnethirtyPM= "Lunch Break",  TwoPM= "Lunch Break",  TwothirtyPM= "Testing", ThreePM= "Testing",  ThreethirtyPM= "Development",  FourPM= "Conference",  FourthirtyPM= "Team Meeting", FivePM= "Team Meeting" },
                new { EmployeeID= "10002",  EmployeeName= "Buchanan",  NineAM= "Task Assign",  NinethirtyAM= "Support",  TenAM= "Support",  TenthirtyAM= "Support", ElevenAM= "Testing",  EleventhirtyAM= "Testing",  TwelvePM= "Testing",  TwelvethirtyPM= "Testing", OnePM= "Lunch Break",  OnethirtyPM= "Lunch Break",  TwoPM= "Lunch Break",  TwothirtyPM= "Development", ThreePM= "Development",  ThreethirtyPM= "Check Mail",  FourPM= "Check Mail",  FourthirtyPM= "Team Meeting", FivePM= "Team Meeting" },
                new { EmployeeID= "10003",  EmployeeName= "Fuller",  NineAM= "Check Mail",  NinethirtyAM= "Check Mail",  TenAM= "Check Mail",  TenthirtyAM= "Analysis Tasks", ElevenAM= "Analysis Tasks",  EleventhirtyAM= "Support",  TwelvePM= "Support",  TwelvethirtyPM= "Support", OnePM= "Lunch Break",  OnethirtyPM= "Lunch Break",  TwoPM= "Lunch Break",  TwothirtyPM= "Development", ThreePM= "Development",  ThreethirtyPM= "Team Meeting",  FourPM= "Team Meeting",  FourthirtyPM= "Development", FivePM= "Development" },
                new { EmployeeID= "10004",  EmployeeName= "Leverling",  NineAM= "Testing",  NinethirtyAM= "Check Mail",  TenAM= "Check Mail",  TenthirtyAM= "Support", ElevenAM= "Testing",  EleventhirtyAM= "Testing",  TwelvePM= "Testing",  TwelvethirtyPM= "Testing", OnePM= "Lunch Break",  OnethirtyPM= "Lunch Break",  TwoPM= "Lunch Break",  TwothirtyPM= "Development", ThreePM= "Development",  ThreethirtyPM= "Check Mail",  FourPM= "Conference",  FourthirtyPM= "Conference", FivePM= "Team Meeting" },
                new { EmployeeID= "10005",  EmployeeName= "Peacock",  NineAM= "Task Assign",  NinethirtyAM= "Task Assign",  TenAM= "Task Assign",  TenthirtyAM= "Task Assign", ElevenAM= "Check Mail",  EleventhirtyAM= "Support",  TwelvePM= "Support",  TwelvethirtyPM= "Support", OnePM= "Lunch Break",  OnethirtyPM= "Lunch Break",  TwoPM= "Lunch Break",  TwothirtyPM= "Development", ThreePM= "Development",  ThreethirtyPM= "Team Meeting",  FourPM= "Team Meeting",  FourthirtyPM= "Testing", FivePM= "Testing" },
            };
            ViewBag.DefaultData = data;
            return View();
        }

Limitations of Merge

The following features have some limitations in Merge:

  • Merge with filter.
  • Merge with wrap text.

Data Validation

Data Validation is used to restrict the user from entering the invalid data. You can use the allowDataValidation property to enable or disable data validation.

  • The default value for allowDataValidation property is true.

Apply Validation

You can apply data validation to restrict the type of data or the values that users enter into a cell.

You can apply data validation by using one of the following ways,

  • Select the Data tab in the Ribbon toolbar, and then choose the Data Validation item.
  • Use the addDataValidation() method programmatically.

Clear Validation

Clear validation feature is used to remove data validations from the specified ranges or the whole worksheet.

You can clear data validation rule by one of the following ways,

  • Select the Data tab in the Ribbon toolbar, and then choose the Clear Validation item.
  • Use the removeDataValidation() method programmatically.

Highlight Invalid Data

Highlight invalid data feature is used to highlight the previously entered invalid values.

You can highlight an invalid data by using one of the following ways,

  • Select the Data tab in the Ribbon toolbar, and then choose the Highlight Invalid Data item.
  • Use the addInvalidHighlight() method programmatically.

Clear Highlighted Invalid Data

Clear highlight feature is used to remove the highlight from invalid cells.

You can clear the highlighted invalid data by using the following ways,

  • Select the Data tab in the Ribbon toolbar, and then choose the Clear Highlight item.
  • Use the removeInvalidHighlight() method programmatically.
tagHelper
dataValidation.cs
Copied to clipboard
<ejs-spreadsheet id="spreadsheet"  created="created" showFormulaBar="false">
<e-spreadsheet-sheets>
    <e-spreadsheet-sheet name="PriceDetails">
        <e-spreadsheet-rows>
            <e-spreadsheet-row>
                <e-spreadsheet-cells>
                    <e-spreadsheet-cell value="Seller Name">
                        <e-spreadsheet-cellstyle fontWeight="Bold" textAlign="Center"></e-spreadsheet-cellstyle>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Customer Id">
                        <e-spreadsheet-cellstyle fontWeight="Bold" textAlign="Center"></e-spreadsheet-cellstyle>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Customer Name">
                        <e-spreadsheet-cellstyle fontWeight="Bold" textAlign="Center"></e-spreadsheet-cellstyle>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Product Name">
                        <e-spreadsheet-cellstyle fontWeight="Bold" textAlign="Center"></e-spreadsheet-cellstyle>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Product Price">
                        <e-spreadsheet-cellstyle fontWeight="Bold" textAlign="Center"></e-spreadsheet-cellstyle>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Sales Date">
                        <e-spreadsheet-cellstyle fontWeight="Bold" textAlign="Center"></e-spreadsheet-cellstyle>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Billing Time">
                        <e-spreadsheet-cellstyle fontWeight="Bold" textAlign="Center"></e-spreadsheet-cellstyle>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Total Price">
                        <e-spreadsheet-cellstyle fontWeight="Bold" textAlign="Center"></e-spreadsheet-cellstyle>
                    </e-spreadsheet-cell
                </e-spreadsheet-cells>
            </e-spreadsheet-row>
            <e-spreadsheet-row>
                <e-spreadsheet-cells>
                    <e-spreadsheet-cell value="John"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="1">
                        <e-cell-validation type="WholeNumber" operator="NotEqualTo" value1="1"></e-cell-validation>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Nash"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Digger">
                        <e-cell-validation type="List" value1="Digger, Digger, Cherrypicker"></e-cell-validation>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="50000">
                        <e-cell-validation type="List" value1="50000,50000,45000"></e-cell-validation>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="04/11/2019"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="11:34:32 AM"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="1,45,000.00"></e-spreadsheet-cell
                </e-spreadsheet-cells>
            </e-spreadsheet-row>
            <e-spreadsheet-row>
                <e-spreadsheet-cells>
                    <e-spreadsheet-cell value="Mike"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="2">
                        <e-cell-validation type="WholeNumber" operator="NotEqualTo" value1="1"></e-cell-validation>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Jim"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Cherrypicker">
                        <e-cell-validation type="List" value1="Cherrypicker, JCB, Wheelbarrow"></e-cell-validation>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="45000">
                        <e-cell-validation type="List" value1="45000,90000,40"></e-cell-validation>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="04/11/2019"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="11:34:32 AM"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="1,45,000.00"></e-spreadsheet-cell
                </e-spreadsheet-cells>
            </e-spreadsheet-row>
            <e-spreadsheet-row>
                <e-spreadsheet-cells>
                    <e-spreadsheet-cell value="shane"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="3">
                        <e-cell-validation type="WholeNumber" operator="NotEqualTo" value1="1"></e-cell-validation>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Sean"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Kango">
                        <e-cell-validation type="List" value1="Kango, Ropes"></e-cell-validation>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="450">
                        <e-cell-validation type="List" value1="450, 95"></e-cell-validation>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="06/25/2019"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="01:30:11 PM"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="545.00"></e-spreadsheet-cell
                </e-spreadsheet-cells>
            </e-spreadsheet-row>
            <e-spreadsheet-row>
                <e-spreadsheet-cells>
                    <e-spreadsheet-cell value="John"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="1">
                        <e-cell-validation type="WholeNumber" operator="NotEqualTo" value1="1"></e-cell-validation>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="Nash"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="JCB">
                        <e-cell-validation type="List" value1="JCB, Ropes, scaffolding"></e-cell-validation>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="90000">
                        <e-cell-validation type="List" value1="90000, 95, 10000"></e-cell-validation>
                    </e-spreadsheet-cell>
                    <e-spreadsheet-cell value="09/22/2019"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="12:30:02 PM"></e-spreadsheet-cell>
                    <e-spreadsheet-cell value="1,00,095.00"></e-spreadsheet-cell
                </e-spreadsheet-cells>
            </e-spreadsheet-row>
           <e-spreadsheet-columns>
                    <e-spreadsheet-column width="88"></e-spreadsheet-column>
                    <e-spreadsheet-column width="88"></e-spreadsheet-column>
                    <e-spreadsheet-column width="106"></e-spreadsheet-column>
                    <e-spreadsheet-column width="98"></e-spreadsheet-column>
                    <e-spreadsheet-column width="88"></e-spreadsheet-column>
                    <e-spreadsheet-column width="86"></e-spreadsheet-column>
                    <e-spreadsheet-column width="107"></e-spreadsheet-column>
                    <e-spreadsheet-column width="81"></e-spreadsheet-column>
                </e-spreadsheet-columns>
        </e-spreadsheet-rows>
    </e-spreadsheet-sheet>
</e-spreadsheet-sheets>
</ejs-spreadsheet>

<script>
    function created() {
        //Add Data Validation to range.
        this.addDataValidation({ type: 'TextLength', Operator: 'LessThanOrEqualTo', Value1: '4' }, 'A2:A5');
        this.addDataValidation({ type: 'WholeNumber', Operator: 'NotEqualTo', Value1: '1' }, 'B2:B5');
        this.addDataValidation({ type: 'Date', Operator: 'NotEqualTo', Value1: '04/11/2019' }, 'F2:F5');
        this.addDataValidation({ type: 'Time', Operator: 'Between', Value1: '10:00:00 AM', value2: '11:00:00 AM' }, 'G2:G5');
        this.addDataValidation({ type: 'Decimal', Operator: 'LessThan', Value1: '100000.00' }, 'H2:H5');
        //Highlight Invalid Data.
        this.addInvalidHighlight('A1:H5');
    }
</script>
Copied to clipboard
public IActionResult Index()
        {
            return View();
        }

Limitations of Data validation

The following features have some limitations in Data Validation:

  • Entire row data validation.
  • Insert row between the data validation.
  • Copy/paste with data validation.
  • Delete cells between data validation applied range.

Clear

Clear feature helps you to clear the cell contents (formulas and data), formats (including number formats, conditional formats, and borders) in a spreadsheet. When you apply clear all, both the contents and the formats will be cleared simultaneously.

Apply Clear Feature

You can apply clear feature by using one of the following ways,

  • Select the clear icon in the Ribbon toolbar under the Home Tab.
  • Using the clear() method to clear the values.

Clear has the following types in the spreadsheet,

Options Uses
Clear All Used to clear all contents, formats, and hyperlinks.
Clear Formats Used to clear the formats (including number formats, conditional formats, and borders) in a cell.
Clear Contents Used to clear the contents (formulas and data) in a cell.
Clear Hyperlinks Used to clear the hyperlink in a cell.

Methods

Clear the cell contents and formats in the Spreadsheet document by using the clear method. The clear method has type and range as parameters. The following code example shows how to clear the cell contents and formats in the button click event.

tagHelper
clearController.cs
Copied to clipboard
<ejs-dropdownbutton id="element" content="Clear" items="ViewBag.items" select="itemSelect"></ejs-dropdownbutton>
<ejs-spreadsheet id="spreadsheet" created="created">
    <e-spreadsheet-sheets>
        <e-spreadsheet-sheet>
            <e-spreadsheet-ranges>
                <e-spreadsheet-range dataSource="ViewBag.DefaultData"></e-spreadsheet-range>
            </e-spreadsheet-ranges>
        </e-spreadsheet-sheet>
    </e-spreadsheet-sheets>
</ejs-spreadsheet>

<script>

   function created() {
        this.cellFormat({ fontWeight: 'bold', fontSize: '12pt'}, 'A1:E1');
        this.cellFormat({ color: '#10c469' }, 'B1:B10');
    }

    function itemSelect(args) {
        var spreadsheet = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet');
        if (args.item.text === 'Clear All')
      spreadsheet.clear({ type: 'Clear All', range: 'D1:D10' }); // Clear the content, formats and hyperlinks applied in the provided range.
    if (args.item.text === 'Clear Formats')
      spreadsheet.clear({ type: 'Clear Formats', range: 'B1:B10' }); // Clear the formats applied in the provided range
    if (args.item.text === 'Clear Contents')
      spreadsheet.clear({ type: 'Clear Contents', range: 'A1:A10' }); // Clear the content in the provided range
    if (args.item.text === 'Clear Hyperlinks')
      spreadsheet.clear({ type: 'Clear Hyperlinks', range: 'F2:F6' }); // Clear the hyperlinks applied in the provided range
    }

</script>
Copied to clipboard
public IActionResult Index()
        {
            List<object> data = new List<object>()
            {
                new { OrderID= "10248",  CustomerID= "VINET",  EmployeeID= "5",  ShipName= "Vins et alcools Chevalier",  ShipCity= "Reims",  Website= "https://www.amazon.com/" },
                new { OrderID= "10249",  CustomerID= "TOMSP",  EmployeeID= "6",  ShipName= "Toms Spezialitäten",  ShipCity= "Münster",  Website= "https://www.overstock.com/" },
                new { OrderID= "10250",  CustomerID= "HANAR",  EmployeeID= "4",  ShipName= "Hanari Carnes",  ShipCity= "Rio de Janeiro",  Website= "https://www.aliexpress.com/" },
                new { OrderID= "10251",  CustomerID= "VICTE",  EmployeeID= "3",  ShipName= "Victuailles en stock",  ShipCity= "Lyon",  Website= "http://www.alibaba.com/" },
                new { OrderID= "10252",  CustomerID= "SUPRD",  EmployeeID= "4",  ShipName= "Suprêmes délices",  ShipCity= "Charleroi",  Website= "https://taobao.com/" },
               
            };
            List<object> items = new List<object>();
            items.Add(new
            {
                text = "Clear All"
            });
            items.Add(new
            {
                text = "Clear Formats"
            });
            items.Add(new
            {
                text = "Clear Contents"
            });
            items.Add(new
            {
                text = "Clear Hyperlinks"
            });
            ViewBag.items = items;
            ViewBag.DefaultData = data;
            return View();
        }

See Also