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

Add extra text above header while exporting Telerik RadGridView in WPF

1 Answer 65 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 19 May 2016, 07:48 AM
While exporting data from Telerik RadGridView in WPF.
How can I add some extra text on above the header? Like if I need to add the name of the company and list name.
Can anyone help me in this regard?

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 20 May 2016, 12:07 PM
Hello Muhammad,

With R1 2016, the new ExportToRadFixedDocument and ExportToWorkbook methods were introduced. You can use them if you need to modify the content of the exported RadGridView and avoid styling the document manually.

Bear in mind that you will need to add the following references:

- Telerik.Windows.Documents.Core.dll
- Telerik.Windows.Documents.Fixed.dll
- Telerik.Windows.Documents.Spreadsheet.dll
- Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.dll
- Telerik.Windows.Zip.dll
- Telerik.Windows.Controls.GridView.Export.dll

Here's an example of how to use them:

private void Export()
{
    //Instantiate the RadFixedDocument object
    RadFixedDocument fixedDoc = this.ExportableGridView.ExportToRadFixedDocument();
 
    //Modify the RadFixedDocument object
    foreach (var page in fixedDoc.Pages)
    {
        var actualPage = page as RadFixedPage;
    }
    //Export the RadFixedDocument to a PDF file
    SaveFileDialog dialog = new SaveFileDialog();
    dialog.DefaultExt = "*.pdf";
    dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", "pdf", "Pdf");
    dialog.FilterIndex = 1;
 
    if (dialog.ShowDialog() == true)
    {
 
        var provider = new PdfFormatProvider();
        using (var output = dialog.OpenFile())
        {
            provider.Export(fixedDoc, output);
        }
 
        System.Diagnostics.Process.Start(dialog.FileName);
    }
}
private void Export()
{
    //Instantiate the Workbook object
    Workbook workbook = this.clubsGrid.ExportToWorkbook();
 
    //Modify the created Workbook
    CellStyle wbStyle = workbook.Styles["Normal"];
    wbStyle.ForeColor = new ThemableColor(Colors.Green);
    wbStyle.FontFamily = new ThemableFontFamily(ThemeFontType.Major);
    wbStyle.FontSize = UnitHelper.PointToDip(16);
    wbStyle.VerticalAlignment = RadVerticalAlignment.Top;
 
    //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);
        }
    }
}

You can also have a look at the RadPdfProcessing and RadSpreadProcessing documentation for more information on how to use RadFixedDocument and Workbook.

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