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

Editing Excel Export

1 Answer 53 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 29 Apr 2016, 07:59 PM
Hi, I used some excel export code previous posted on a thread. It works great, but I'm wondering if we can intercept midway. I'm looking to add a value on the top row then followed by the chart.

public static void Export(RadGridView grid)
{
    const string extension = "xls";
 
    var dialog = new SaveFileDialog
    {
        DefaultExt = extension,
        Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
        FilterIndex = 1
    };
 
    if (dialog.ShowDialog() != true)
    {
        return;
    }
 
    using (var stream = dialog.OpenFile())
    {
        var exportOptions = new GridViewExportOptions
        {
            Format = ExportFormat.ExcelML,
            ShowColumnHeaders = true,
            ShowColumnFooters = true,
            ShowGroupFooters = false,
        };
        exportOptions.Items = (IEnumerable)grid.ItemsSource;
        grid.Export(stream, exportOptions);
    }
}

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 03 May 2016, 09:55 AM
Hello Minh,

RadGridView provides two events which fire when you export data from RadGridView in the ExcelML format - ElementExporting and ElementExported. You can handle them in order to format the cell values to be exported or if you want to write additional data to the stream.

I hope you find this information helpful.

Regards,
Dilyan Traykov
Telerik
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
Minh
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or