# Excel Export

The Grid enables you to export its content to Excel.

For a runnable example, refer to the [demo on Excel export by the Grid](https://demos.telerik.com/aspnet-core/grid/excel-export).

## Getting Started

To enable the Excel export option of the Grid:

1. Include the [toolbar configuration](https://www.telerik.com/aspnet-core-ui/documentation/api/kendo.mvc.ui.fluent/gridtoolbarcommandfactory#excel).
2. Set the [export options](https://www.telerik.com/aspnet-core-ui/documentation/api/kendo.mvc.ui.fluent/gridexcelsettingsbuilder).
3. To take full advantage of the Excel export feature, download the JSZip library and include the file before the Kendo UI JavaScript files in the `Layout.cshtml`. For more information, refer to the article with the [requirements](https://www.telerik.com/aspnet-core-ui/documentation/installation/system-requirements/export-support#jszip-library).

   ```Razor HtmlHelper
       <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
       <script src="https://unpkg.com/jszip/dist/jszip.min.js"></script>
       <script src="https://cdn.jsdelivr.net/npm/@@progress/kendo-ui@2026.4.1111/umd/kendo.all.min.js"></script>

       @(Html.Kendo().Grid<ProductViewModel>()
           .Name("grid")
           .ToolBar(tools => tools.Excel())
           .Excel(excel => excel
               .FileName("Products.xlsx")
           .DataSource(dataSource => dataSource
               .Ajax()
               .Read(read => read.Action("Products_Read", "Home"))
           )
       )
   ```

   ```Razor TagHelper
       <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
       <script src="https://unpkg.com/jszip/dist/jszip.min.js"></script>
       <script src="https://cdn.jsdelivr.net/npm/@@progress/kendo-ui@2026.4.1111/umd/kendo.all.min.js"></script>

       <kendo-grid name="grid">
           <toolbar>
               <toolbar-button name="excel"></toolbar-button>
           </toolbar>
           <excel file-name="Products.xlsx" />
           <datasource type="DataSourceTagHelperType.Ajax">
               <transport>
                   <read url="@Url.Action("Products_Read","Home")" />
               </transport>
           </datasource>
       </kendo-grid>
   ```

To initiate the Excel export, press the **Toolbar** button or use the [Grid client-side API](https://docs.telerik.com/kendo-ui/api/ui/grid) and call the [`saveAsExcel`](https://docs.telerik.com/kendo-ui/api/ui/grid/methods/saveasexcel) method.

> Browser versions, such as Internet Explorer 9 and earlier, and Safari, require the implementation of a server proxy.

```C#
    [HttpPost]
    public ActionResult Pdf_Export_Save(string contentType, string base64, string fileName)
    {
        var fileContents = Convert.FromBase64String(base64);

        return File(fileContents, contentType, fileName);
    }
```

## Outputting the Result

Through its default configuration, the Telerik UI Grid for ASP.NET Core exports the current page of the data with sorting, filtering, grouping, and aggregates applied. To export all pages, refer to the section on [exporting all data](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/grid/export/excel-export#exporting-all-data).

The Grid uses the current column order, visibility, and dimensions to generate the Excel file. It does not export the current CSS theme in the Excel file. For more information on changing the visual appearance of the Excel document, refer to the section about [customizing the Excel documents](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/grid/export/excel-export#customizing-excel-documents).

> * The Grid exports only data-bound columns. Template and command columns are ignored.
> * The `Format` option is not used during export. For more information, refer to the section about [defining the column format](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/grid/export/excel-export#defining-the-column-format).
> * The `ClientTemplate` option is not used during export. For more information, refer to the section on [setting the column templates](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/grid/export/excel-export#setting-the-column-templates).

## Exporting All Data

By default, the Telerik UI Grid for ASP.NET Core exports only the current page of data. To export all pages, set the `AllPages` option to `true`.

> When you have enabled the `AllPages` option as `true`, the Grid makes a `read` request for all data. If the data items are many, the browser may become unresponsive. For such scenarios, implement a server-side export.

```Razor HtmlHelper
    @(Html.Kendo().Grid<ProductViewModel>()
        .Name("grid")
        .ToolBar(tools => tools.Excel())
        .Excel(excel => excel
            .AllPages(true)
        )
        .DataSource(dataSource => dataSource
            .Ajax()
            .Read(read => read.Action("Products_Read", "Home"))
        )
    )
```

```Razor TagHelper
    <kendo-grid name="grid">
        <toolbar>
            <toolbar-button name="excel"></toolbar-button>
        </toolbar>
        <excel all-pages="true" />
        <datasource type="DataSourceTagHelperType.Ajax">
            <transport>
                <read url="@Url.Action("Products_Read","Home")" />
            </transport>
        </datasource>
    </kendo-grid>
```

## Customizing Excel Documents

The [`ExcelExport()`](https://www.telerik.com/aspnet-core-ui/documentation/api/kendo.mvc.ui.fluent/grideventbuilder#excelexportsystemstring) event allows the customization of the generated Excel document. The `workbook` event argument exposes the generated Excel workbook configuration. For more information on how Excel documents work, refer to the article on [Excel export in Kendo UI for jQuery](https://docs.telerik.com/kendo-ui/framework/excel/introduction).

1. Attach an Excel export handler.

   ```Razor HtmlHelper
       @(Html.Kendo().Grid<OrderViewModel>()
           .Name("grid")
           .ToolBar(tools => tools.Excel())
           .Events(e => e.ExcelExport("excelExport"))
           /* Other configuration. */
       )
   ```

   ```Razor TagHelper
       <kendo-grid name="grid" on-excel-export="excelExport">
           <toolbar>
               <toolbar-button name="excel"></toolbar-button>
           </toolbar>
           
       </kendo-grid>
   ```

2. In the handler, manipulate the generated workbook. The example alternates the [background color of the row cells](https://docs.telerik.com/kendo-ui/api/ooxml/workbook/configuration/sheets.rows.cells.background).

   ```JS
   <script>
       function excelExport(e) {
           var sheet = e.workbook.sheets[0];
           for (var rowIndex = 1; rowIndex < sheet.rows.length; rowIndex++) {
               if (rowIndex % 2 == 0) {
                   var row = sheet.rows[rowIndex];
                   for (var cellIndex = 0; cellIndex < row.cells.length; cellIndex++) {
                       row.cells[cellIndex].background = "#aabbcc";
                   }
               }
           }
       }
   </script>
   ```

## Exporting Right-to-Left Content

The [`ExcelExport()`](https://www.telerik.com/aspnet-core-ui/documentation/api/kendo.mvc.ui.fluent/grideventbuilder#excelexportsystemstring) event allows you to reverse the cells and set the text alignment to support right-to-left (RTL) languages. To render the document in the right-to-left flow in Excel, enable the [`rtl`](https://docs.telerik.com/kendo-ui/api/ooxml/workbook/configuration/rtl) option of the workbook.

Each row has a `type` field that can be used to distinguish between the various row types in the Grid. The supported values are:

* `"header"`
* `"footer"`
* `"group-header"`
* `"group-footer"`
* `"data"`

## Setting the Column Templates

The Telerik UI Grid for ASP.NET Core does not use the `ClientTemplate` during Excel export. It exports only the data. The reason is that a column template may contain arbitrary HTML which cannot be converted to Excel column values. Here is how to use a column template that does not contain HTML:

1. Attach an Excel export handler.

   ```Razor HtmlHelper
       @(Html.Kendo().Grid<OrderViewModel>()
           .Name("grid")
           .ToolBar(tools => tools.Excel())
           .Events(e => e.ExcelExport("excelExport"))
           .Columns(columns => {
               columns.Bound(p => p.OrderID).Filterable(false).Width(100);
               columns.Bound(p => p.Freight).ClientTemplate("Freight: #: kendo.format('{0:c}', Freight) #");
           })
           /* Other configuration. */
       )
   ```

   ```Razor TagHelper
       <kendo-grid name="grid" on-excel-export="excelExport">
           <toolbar>
               <toolbar-button name="excel"></toolbar-button>
           </toolbar>
           <columns>
               <column field="OrderID" width="100">
                   <filterable enabled="false"/>
               </column>
               <column field="Freight" width="100" template="Freight: #: kendo.format('{0:c}', Freight) #" />
           </columns>
           
       </kendo-grid>
   ```

2. In the handler, manipulate the generated workbook. The example applies the column template to the cell by assigning it to the [rows.cells.value](https://docs.telerik.com/kendo-ui/api/ooxml/workbook/configuration/sheets.rows.cells.value).

   ```JS
   <script>
       function excelExport(e) {
           var sheet = e.workbook.sheets[0];
           var template = kendo.template(e.sender.columns[1].template);
           var data = e.sender.dataSource.view();
           for (var i = 0; i < data.length; i++) {
               sheet.rows[i + 1].cells[1].value = template(data[i]);
           }
       }
   </script>
   ```

## Defining the Column Format

The Telerik UI Grid for ASP.NET Core does not use the `Format` option during Excel export because some formats are incompatible with Excel. To format the cell values, set the Kendo UI for jQuery [`format`](https://docs.telerik.com/kendo-ui/api/ooxml/workbook.html#configuration-sheets.rows.cells.format) option of the cells.

The [page on creating a custom number format](https://support.office.com/en-us/article/Create-a-custom-number-format-78f2a361-936b-4c03-8772-09fab54be7f4) describes the formats that are supported by Excel.

1. Attach an excel export handler.

   ```Razor HtmlHelper
       @(Html.Kendo().Grid<OrderViewModel>()
           .Name("grid")
           .ToolBar(tools => tools.Excel())
           .Events(e => e.ExcelExport("excelExport"))
           .Columns(columns => {
               columns.Bound(p => p.OrderID).Filterable(false).Width(100);
               columns.Bound(p => p.Freight).ClientTemplate("Freight: #: kendo.format('{0:c}', Freight) #");
           })
           /* Other configuration. */
       )
   ```

   ```Razor TagHelper
       <kendo-grid name="grid" on-excel-export="excelExport">
           <toolbar>
               <toolbar-button name="excel"></toolbar-button>
           </toolbar>
           <columns>
               <column field="OrderID" width="100">
                   <filterable enabled="false"/>
               </column>
               <column field="Freight" width="100" template="Freight: #: kendo.format('{0:c}', Freight) #" />
           </columns>
           
       </kendo-grid>
   ```

2. In the handler, manipulate the generated workbook. The example applies a format to the cell by assigning it to the [rows.cells.format](https://docs.telerik.com/kendo-ui/api/ooxml/workbook/configuration/sheets.rows.cells.format)

   ```JS
   <script>
       function excelExport(e) {
           var sheet = e.workbook.sheets[0];
           for (var rowIndex = 1; rowIndex < sheet.rows.length; rowIndex++) {
               var row = sheet.rows[rowIndex];
               row.cells[1].format = "[Blue]#,##0.0_);[Red](#,##0.0);0.0;"
           }
       }
   </script>
   ```

## Server-Side Processing

To export large datasets to Excel, use the [RadSpreadStreamProcessing library](https://docs.telerik.com/devtools/document-processing/libraries/radspreadstreamprocessing/overview) which is part of [Telerik Document Processing (TDP) by Progress](https://docs.telerik.com/devtools/document-processing/introduction).

## Excluding Columns from Exporting

In some scenarios, you will want to hide given column or multiple columns from being exported. This can be achieved using the [`Exportable`](https://docs.telerik.com/kendo-ui/api/ui/grid/configuration/columns.exportable) setting.

```Razor HtmlHelper
    columns.Bound(p => p.ProductName).Exportable(false);
```

```Razor TagHelper
    <column field="ProductName">
        <exportable enabled="false"/>
    </column>
```

You can also set `Exportable` in a detailed fashion to include different values for Excel and PDF exporting modes, providing separate options for each:

```Razor HtmlHelper
    columns.Bound(p => p.ProductName).Exportable(x=> x.Pdf(true).Excel(false));
```

```Razor TagHelper
    <column field="ProductName">
        <exportable enabled="true" pdf="true" excel="false"/>
    </column>
```

## Exporting Hidden Columns

To export a field that is not displayed in the Grid, define a bound column and hide it with `.Hidden(true)`. Explicitly enable Excel export for that column; `.Exportable(true)` alone does not include hidden columns. The field must be available in the Grid's data items.

Add the following column to the Grid's column configuration after you [enable Excel export](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/grid/export/excel-export#getting-started):

```Razor HtmlHelper
    columns.Bound(p => p.ProductName)
        .Hidden(true)
        .Exportable(exportable => exportable.Pdf(false).Excel(true));
```

```Razor TagHelper
    @addTagHelper *, Kendo.Mvc

    <column field="ProductName" hidden="true">
        <exportable pdf="false" excel="true" />
    </column>
```

Place the `<column>` element inside the Grid's `<columns>` element. Use `hidden="true"`, not `visible="false"`, to retain the column configuration for export.

The column remains hidden in the Grid and appears in the exported Excel file. `.Hidden(true)` hides the column visually with CSS, whereas `.Visible(false)` prevents the column from rendering.

## Known Limitations

* During export, the Grid initializes a new instance of its DataSource based on the original configuration. This triggers an additional `read` request to fetch the data, regardless of whether the [`AllPages`](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/grid/export/excel-export#exporting-all-data) option is enabled or disabled. The behavior ensures that the export process does not alter the state of the original DataSource.
* The Grid and its DataSource contain only the data items from the current page during client-side export. As a result, either make the export in chunks, or disable the paging feature.
* The maximum size of the exported file has a system-specific limit. For large data sets, use the server-side solution which is provided by the [RadSpreadStreamProcessing](https://docs.telerik.com/devtools/document-processing/libraries/radspreadstreamprocessing/overview) as part of the [Document Processing Library](https://docs.telerik.com/devtools/document-processing/introduction).
* Exporting the Grid to Excel in older browsers, such as Internet Explorer 9 and Safari, requires the implementation of a server proxy. For more information, refer to [the `ProxyURL` configuration section](https://www.telerik.com/aspnet-core-ui/documentation/api/kendo.mvc.ui.fluent/gridexcelsettingsbuilder#proxyurlsystemstring).
* The Grid does not use the column [`ClientTemplate`](https://www.telerik.com/aspnet-core-ui/documentation/api/kendo.mvc.ui.fluent/gridboundcolumnbuilder#clienttemplatesystemstring) during the Excel export—it exports only the data. The reason for this behavior is that a column template has a chance to contain arbitrary HTML which cannot be converted to Excel column values. For more information on how to use a column template that does not contain HTML, refer to [this column template example](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/data-management/grid/export/excel-export#setting-the-column-templates).
* The Grid does not export its [`ClientDetailTemplateId`](https://www.telerik.com/aspnet-core-ui/documentation/api/kendo.mvc.ui.fluent/gridbuilder#clientdetailtemplateidsystemstring) for the same reason as it does not export its column templates.
* The Grid does not use [column formats](https://www.telerik.com/aspnet-core-ui/documentation/api/kendo.mvc.ui.fluent/gridboundcolumnbuilder#formatsystemstring) during the Excel export because some Kendo UI formats are incompatible with Excel. To format the cell values, set the cell [`format`](https://docs.telerik.com/kendo-ui/api/ooxml/workbook/configuration/sheets.rows.cells.format) option of the cells.

For more information on the formats that are supported by Excel, refer to [this page](https://support.office.com/en-us/article/Create-a-custom-number-format-78f2a361-936b-4c03-8772-09fab54be7f4).

## See Also

* [ASP.NET Core DataGrid Homepage](https://www.telerik.com/aspnet-core-ui/grid)

* [Excel Export by the Grid HtmlHelper for ASP.NET Core (Demo)](https://demos.telerik.com/aspnet-core/grid/excel-export)

* [Copying to Excel by the Grid HtmlHelper for ASP.NET Core (Demo)](https://demos.telerik.com/aspnet-core/grid/copy-to-excel)

* [Server-Side API](https://www.telerik.com/aspnet-core-ui/documentation/api/grid)
