New to Telerik UI for ASP.NET Core? Start a free 30-day trial
Format Cells when Exporting Grid to Excel
Environment
Product | Telerik UI for ASP.NET Core Grid |
Product version | 2025.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:
-
Handle the
ExcelExport
event of the Grid:Razor.Events(e => e.ExcelExport("excelExport"))
-
Within the
ExcelExport
event handler, loop through the rows in the sheet, select the cell by index, which value must be formatted, and use theformat
option to set the desired format:JSfunction 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.