New to Telerik UI for ASP.NET MVCStart a free 30-day trial

Format Cells when Exporting Grid to Excel

Environment

ProductTelerik UI for ASP.NET MVC Grid
Product version2025.1.227

Description

How can I format the cells during the Excel export of the Grid's data?

Solution

The example relies on the following key steps:

  1. Handle the ExcelExport event of the Grid:

    Razor
    .Events(e => e.ExcelExport("excelExport"))
  2. Within the ExcelExport event handler, loop through the rows in the sheet, select the cell by index, which value must be formatted, and use the format option to set the desired format:

    JS
    function excelExport(e) {
        var sheet = e.workbook.sheets[0];
        for (var rowIndex = 1; rowIndex < sheet.rows.length; rowIndex++) {
            var sheet = e.workbook.sheets[0];
    
            for (var rowIndex = 1; rowIndex < sheet.rows.length; rowIndex++) {
                var row = sheet.rows[rowIndex];
                // Change the format in the third cell.
                row.cells[2].format = "yyyy-MM-dd"
            }
        }
    }

For additional guidance on the supported Excel formats, refer to the Microsoft's documentation.

To review the complete example, refer to the ASP.NET MVC project on formatting the cells in the Grid Excel exports.

The solution requires Telerik UI for ASP.NET MVC 2014.3.1125 version or later. Earlier versions do not expose the ExcelExport event through the fluent API.

More ASP.NET MVC Grid Resources

See Also