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:
ExcelMLDataType.DateTime - in order to have a DateTime column exported, you must also set a valid ExcelMLStyle specifying a correct format
ExcelMLDataType.Boolean
ExcelMLDataType.String
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";
}
}
}
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);
}
InitializingExcelMLStyles event will be only raised when exporting with ExportFormat.ExcelML