# Changing the Date Format in Excel Files Exported from UI Grid Components

Apply a custom date format to grid data exported to Excel with RadSpreadProcessing.

## Environment

| Version    | Product             | Author                                                                          |
| ---------- | ------------------- | ------------------------------------------------------------------------------- |
| 2025.3.806 | RadSpreadProcessing | [Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova) |

## Description

Learn how to apply a custom date format (for example, "yyyy-MM-dd") to the relevant columns in the exported Excel file generated from UI Grid components offered by the Telerik family.

<img style="border: 1px solid gray;" src="/document-processing-libraries/documentation/assets/0c9080acaf3d70600a9daa2a70f3fa0d/changing-date-format-exported-excel-blazor-grid.png" alt="Excel Date column before and after formatting: 4/13/07 12:00 AM becomes 2007-04-13." />

## Solution

To change the date format in the exported Excel file, use [RadSpreadProcessing](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/overview) to modify the exported stream before saving the file.

Follow these steps:

1. Export the grid data to a `MemoryStream`.
2. Load the exported stream into a workbook using the [XlsxFormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/import-and-export-to-excel-file-formats/xlsx/xlsxformatprovider).
3. Apply a custom [date format](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/features/format-codes#date-and-time-formatting) to the desired column in the workbook.
4. Save the modified workbook to a file.

Here is an example implementation:

```csharp
static void Main(string[] args)
{
    // Step 1: Export the grid data to a MemoryStream
    var exportedExcelStream = new MemoryStream(File.ReadAllBytes("exported-grid.xlsx"));

    // Step 2: Load the exported stream into a workbook
    XlsxFormatProvider formatProvider = new XlsxFormatProvider();
    Workbook workbook = formatProvider.Import(exportedExcelStream, TimeSpan.FromSeconds(10));

    // Step 3: Apply date format to the desired column (e.g., column index 2 for Dates)
    CellValueFormat dateFormat = new CellValueFormat("yyyy-MM-dd");
    ColumnSelection dateColumn = workbook.Worksheets[0].Columns[2]; // Update index as needed
    dateColumn.SetFormat(dateFormat);

    // Step 4: Save the modified workbook to a file
    string outputFilePath = "formatted.xlsx";
    File.WriteAllBytes(outputFilePath, formatProvider.Export(workbook, TimeSpan.FromSeconds(10)));
    Process.Start(new ProcessStartInfo() { FileName = outputFilePath, UseShellExecute = true });
}
```

### Explanation

* **Step 1:** Reads the exported Excel file into a `MemoryStream`.
* **Step 2:** Uses `XlsxFormatProvider` to parse the stream into a `Workbook` object for manipulation.
* **Step 3:** Sets a custom date format for the targeted column using `SetFormat`.
* **Step 4:** Saves the updated workbook and opens the file using the default application.

## See Also

* [XlsxFormatProvider](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/formats-and-conversion/import-and-export-to-excel-file-formats/xlsx/xlsxformatprovider)
* [Date and Time Formatting](https://www.telerik.com/document-processing-libraries/documentation/libraries/radspreadprocessing/features/format-codes#date-and-time-formatting)
