Export Telerik RadGridView to specific Excel sheet name

2 posts, 0 answers
  1. Gorka Sologuren
    Gorka Sologuren avatar
    4 posts
    Member since:
    Feb 2009

    Posted 29 Jul Link to this post

    How I can export a table to a specific Excel sheet ?


    <p>string file = this.radGridView.ToExcelML(objects, true);</p><p>File.WriteAllText("F:\\test.xls", file);</p>


    The export works correctly. But I generates a file in a default sheet "WorkSheet" I would like to indicate the name of the sheet in the export.

  2. Dilyan Traykov
    Dilyan Traykov avatar
    371 posts

    Posted 01 Aug Link to this post


    I'm afraid that the desired behavior cannot be achieved using RadGridView's ToExcelML method. You could, however, use the newly-introduced ExportToWorkbook method, like so:

    //Instantiate the Workbook object
    Workbook workbook = this.clubsGrid.ExportToWorkbook();
    workbook.ActiveWorksheet.Name = "Clubs";
    //Export the Workbook to an Excel file
    SaveFileDialog dialog = new SaveFileDialog();
    dialog.DefaultExt = "*.xlsx";
    dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", "xlsx", "Excel");
    dialog.FilterIndex = 1;
    if (dialog.ShowDialog() == true)
        var provider = new XlsxFormatProvider();
        using (var output = dialog.OpenFile())
            provider.Export(workbook, output);

    Do let me know if such an approach would be suitable for you.

    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top