Prevent the default export functionality by canceling the ExportToExcel command in the ItemCommand event.
Generate a Workbook out of the RadGrid using the GenerateXslxOutput<Workbook>() method, introduced in R1 2021. (Creating the workbook will give you the flexibility to modify and adjust the structure).
Remove the rows corresponding to the filtering item and to command item (if such is shown) from the Workbook.
Export the modified Workbook to xlsx file with the XlsxFormatProvider and send it as a response to the browser.
protectedvoidRadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
if (e.CommandName == RadGrid.ExportToExcelCommandName)
//prevent the default exporting
e.Canceled = true;
//generate Workbook out of the Grid for exporting
DPL.Workbook workbook = RadGrid1.MasterTableView.GenerateXlsxOutput<DPL.Workbook>() as DPL.Workbook;
DPL.Worksheet worksheet = workbook.ActiveSheet as DPL.Worksheet;
//remove the command item from the exported workbookvar commandRowIndex = 0;
DPL.RowSelection commandRow = worksheet.Rows[commandRowIndex];
//alternative approach to remove the command item//RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;//RadGrid1.Rebind();//remove the filter item from the exported workbookvar filterRowIndex = 1;
DPL.RowSelection filterRow = worksheet.Rows[filterRowIndex];
//export and send to the browser as responsebyte data;
using (MemoryStream ms = new MemoryStream())
var provider = new XlsxFormatProvider();
data = ms.ToArray();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + RadGrid1.ExportSettings.FileName + ".xlsx");
Doncho Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.