New to Telerik UI for ASP.NET MVC? Start a free 30-day trial
Format Cells when Exporting Grid to Excel
Environment
Product | Telerik UI for ASP.NET MVC 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.
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.