# Format Cells when Exporting Grid to Excel

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Grid</td>
 </tr>
 <tr>
  <td>Product version</td>
  <td>2025.1.227</td>
 </tr>
</table>

## 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`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/grideventbuilder#excelexportsystemstring) event of the Grid:

   ```Razor HtmlHelper
   .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`](https://docs.telerik.com/kendo-ui/api/ooxml/workbook.html#configuration-sheets.rows.cells.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](https://support.office.com/en-us/article/Create-a-custom-number-format-78f2a361-936b-4c03-8772-09fab54be7f4).

To review the complete example, refer to the ASP.NET MVC project on [formatting the cells in the Grid Excel exports](https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Areas/GridExcelExportCellFormat).

> 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

* [ASP.NET MVC Grid Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/overview)

* [ASP.NET MVC Grid Demos](https://demos.telerik.com/aspnet-mvc/grid/index)

* [ASP.NET MVC Grid Product Page](https://www.telerik.com/aspnet-mvc/grid)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/grid)

* [Server-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/grid)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
