# Export Selected Grid Rows to Excel

## Environment

<table>
    <tbody>
	    <tr>
	    	<td>Product</td>
	    	<td>Progress® Kendo UI for Angular Grid</td>
	    </tr>
    </tbody>
</table>

## Description

How can I export only the selected rows of the Kendo UI for Angular Grid to Excel?

This article also answers the following questions:

* How can I export checked rows from the Grid?
* What is the method to export selected grid rows to Excel in Angular?
* How to use selection in the Kendo UI Grid for Angular to export to Excel?

## Solution

The following example demonstrates how to export only selected rows to Excel.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/knowledge-base/export-selected-rows-excel/source.txt)

By default, the Excel export functionality of the Grid generates a file containing the current data of the component. To export specific data to Excel that includes only the selected Grid rows:

1. Use the [`kendoGridSelectBy`](https://www.telerik.com/kendo-angular-ui/components/grid/api/selectiondirective) directive of the Grid to store the selected items in the [`selectedKeys`](https://www.telerik.com/kendo-angular-ui/components/grid/api/selectiondirective#selectedkeys) collection that the directive provides:

   ```html
   <kendo-grid
       ...
       kendoGridSelectBy
       [(selectedKeys)]="mySelection"
   ></kendo-grid>
   ```

2. Use the [`fetchData`](https://www.telerik.com/kendo-angular-ui/components/grid/api/excelcomponent#fetchdata) callback of the `ExcelComponent` to specify the data to be exported in Excel.

   ```html
   <kendo-grid ... >
       ...
       <kendo-grid-excel [fetchData]="allData" fileName="Products.xlsx" ></kendo-grid-excel>
   </kendo-grid>
   ```

   In the `fetchData` callback, return an `ExcelExportData` object that contains only the items that are selected according to the `selectedKeys` collection.

   > Make sure the `fetchData` handler is an arrow function which retains the correct `this` context.

   ```ts
   public mySelection: number[] = [];
   public selectedData = ():ExcelExportData =>{
     const result = {
       data: this.mySelection,
     };
     return result;
   }
   ```

## See Also

* [Export Selected Rows to PDF](https://www.telerik.com/kendo-angular-ui/components/knowledge-base/export-selected-rows-pdf)
* [Export All Data to Excel](https://www.telerik.com/kendo-angular-ui/components/grid/export/excel-export#controlling-the-exported-data)
* [Kendo UI for Angular Grid Row Selection](https://www.telerik.com/kendo-angular-ui/components/grid/selection/row-selection)
* [Kendo UI for Angular Grid Excel Export](https://www.telerik.com/kendo-angular-ui/components/grid/export/excel-export)
* [API Reference of the Grid Component](https://www.telerik.com/kendo-angular-ui/components/grid/api/gridcomponent)
