New to Telerik UI for ASP.NET Core? Download free 30-day trial

Formatting Cells When Exporting the Grid to Excel


Product Version 2022.2.621
Product Telerik UI for ASP.NET Core Grid


How can I format the cell values during the export of the Grid to Excel?


Use the format option of the Workbook cell to set the format of the cell value.

  1. Handle the ExcelExport event of the Grid.
  2. Get the Workbook sheet and loop through the array of the sheet rows.
  3. Specify the required cell format.
        .Columns(columns =>
            columns.Bound(p => p.ProductName);
            columns.Bound(p => p.UnitPrice);
            columns.Bound(p => p.UnitsOnOrder);
            columns.Bound(p => p.UnitsInStock);
        .Events(e => e.ExcelExport("excelExport"))
        .ToolBar(tools => tools.Excel())
        .Excel(excel => excel
            .FileName("Kendo UI Grid Export.xlsx")
        .Reorderable(r => r.Columns(true))
        .Resizable(r => r.Columns(true))
        .DataSource(dataSource => dataSource
            .Read(read => read.Action("Excel_Export_Read", "Grid"))
        function excelExport(e) {
            var sheet = e.workbook.sheets[0]; //Workbook sheet.
            for (var rowIndex = 1; rowIndex < sheet.rows.length; rowIndex++) {
                var row = sheet.rows[rowIndex];
                row.cells[1].format = "[Red](#,##0.0);0.0;" //Format the data in the second column.

For a runnable example based on the code above, see the REPL project on formatting cells when exporting the Grid to Excel.

More ASP.NET Core Grid Resources

See Also

In this article