New to Telerik UI for WPF? Download free 30-day trial

Style Exported ExcelML

You can use the ExportFormat.ExcelML to export RadGridView's content to a "xls" file. An example is available in the Grid Export article.

Set Exported Element's VisualParameters

You can utilize the ElementExporting event as of Q3 2013 GridViewElementExportingEventArgs exposes a new argument VisualParameters. Please note that it is only valid when exporting with ExportFormat.ExcelML and ExportFormat.Html.

The VisualParameters property for this format is of type GridViewExcelMLVisualExportParameters. It has three public properties:

  • StyleId

  • DataType:

    1. ExcelMLDataType.DateTime - in order to have a DateTime column exported, you must also set a valid ExcelMLStyle specifying a correct format

    2. ExcelMLDataType.Boolean

    3. ExcelMLDataType.String

    4. ExcelMLDataType.Number

  • RowHeight

Please note that you should first have set a valid Style in order to assign it when the ElementExporting event is raised.

The RowHeight property applies when the exported element is Row. The DataType property applies when exported element is Cell.

For example:

Example 1: Set the style of the exported element

private void clubsGrid_ElementExporting(object sender, GridViewElementExportingEventArgs e) 
{ 
    if (e.Element == ExportElement.Cell) 
    { 
        var column = e.Context as GridViewDataColumn; 
        if (column.Header.ToString() == "Name") 
        { 
            (e.VisualParameters as GridViewExcelMLVisualExportParameters).StyleId = "someStyle"; 
        } 
    } 
} 
You can define the Style when InitializingExcelMLStyles event is raised. For example:

Example 2: Define a style:

private void clubsGrid_InitializingExcelMLStyles(object sender, ExcelMLStylesEventArgs e) 
{ 
    ExcelMLStyle style = new ExcelMLStyle("someStyle"); 
    style.Alignment.Horizontal = ExcelMLHorizontalAlignment.Automatic; 
    style.Font.Size = 15; 
    style.Font.Italic = true; 
    e.Styles.Add(style); 
} 
You can check the Export Events article for more information on how to define an ExcelMLStyle.

InitializingExcelMLStyles event will be only raised when exporting with ExportFormat.ExcelML

See Also

In this article