Search results

Cell Range in ASP.NET Core Spreadsheet control

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
<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>
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();
        }

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
<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>
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();
        }

See Also