Completed
Last Updated: 30 Nov 2020 14:21 by ADMIN
Release R1 2021
Rodney
Created on: 04 Mar 2019 15:22
Category: Grid
Type: Feature Request
3
Create WorkSheetName property for RadGrid when exporting to XLSX
There should be RadGrid.ExportSettings.WorksheetName property to name a Sheet inside the Excel file, instead of having it named after the RadGrid.ExportSettings.FileName property as well as to avoid additional coding to Work around this.
1 comment
ADMIN
Doncho
Posted on: 18 Jun 2020 16:56

Thanks for sharing that idea for a built-in feature!

Currently, one way to set the name of the sheet in the exported Excel file is by using the InfrastructureExporting event of RadGrid.

Sample C# code:

protected void RadGrid1_InfrastructureExporting(object sender, GridInfrastructureExportingEventArgs e)
{
    ExportStructure.ExportStructure structure = e.ExportStructure;
 
    // Render the structure to XLSX format and return it to a byte array
    ExportStructure.XlsxRenderer renderer = new ExportStructure.XlsxRenderer(structure);
    byte[] xlsxByteArray = renderer.Render();
 
    // create an format provider instance
    XLSX.XlsxFormatProvider formatProvider = new XLSX.XlsxFormatProvider();
    // import the newly created document into a Workbook
    WB.Workbook myWorkbook = formatProvider.Import(xlsxByteArray);
 
    myWorkbook.Worksheets[0].Name = "MySheet";
 
    // once finished with changes convert the workbook back to byte array
    byte[] data = formatProvider.Export(myWorkbook);
 
    // return the byte array for downloading.
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.Headers.Remove("Content-Disposition");
    Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}.xlsx", RadGrid1.ExportSettings.FileName));
    Response.BinaryWrite(data);
    Response.End();
}

Related resources:

 

    Kind regards,
    Doncho
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.