Completed
Last Updated: 26 Mar 2021 16:06 by ADMIN
Release R1 2021 SP2
James
Created on: 19 Feb 2021 12:53
Category: Grid
Type: Bug Report
1
Export to Xslx adding blank row for filter item in R1 2021
Empty row is added for the filter item in the export file, even if the [FilteringItem].Visible is set to false.
2 comments
ADMIN
Doncho
Posted on: 26 Mar 2021 16:06

Hi James,

The problem has been resolved and the fix will appear on March 30, 2021, with the R1 2021 SP2 release.

Kind regards,
Doncho
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

ADMIN
Doncho
Posted on: 05 Mar 2021 15:19

Workaround for the issue:

  • 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.

C# code:

 

protected void RadGrid1_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 workbook
        var commandRowIndex = 0;
        DPL.RowSelection commandRow = worksheet.Rows[commandRowIndex];
        commandRow.Remove();
        //alternative approach to remove the command item
        //RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
        //RadGrid1.Rebind();

        //remove the filter item from the exported workbook
        var filterRowIndex = 1;
        DPL.RowSelection filterRow = worksheet.Rows[filterRowIndex];
        filterRow.Remove();

        //export and send to the browser as response
        byte[] data;
        using (MemoryStream ms = new MemoryStream())
        {
            var provider = new XlsxFormatProvider();
            provider.Export(workbook, ms);
            data = ms.ToArray();
        }
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        Response.Headers.Remove("Content-Disposition");
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + RadGrid1.ExportSettings.FileName + ".xlsx");
        Response.BinaryWrite(data);
        Response.End();
    }
}

 

Kind regards,
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/.