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

Format Cells when Exporting Grid to Excel

Environment

ProductTelerik UI for ASP.NET Core 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.You can use this as a starting point to configure the same behavior in an ASP.NET Core project.

More ASP.NET Core Grid Resources

See Also