This is a migrated thread and some comments may be shown as answers.

Export Telerik RadGridView to specific Excel sheet name

1 Answer 88 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gorka S.
Top achievements
Rank 1
Gorka S. asked on 29 Jul 2016, 12:44 PM

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.

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 01 Aug 2016, 12:26 PM
Hello,

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.

Regards,
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.
Tags
GridView
Asked by
Gorka S.
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or