Edit this page

Export Numeric Value

PROBLEM

When exporting a RadGridView to Excel using ExportFormat.ExcelML, if you have applied a DataFormatString for a certain column of type integer, the values are exported as strings.

CAUSE

The content of each cell within the column is treated as string due to the formatting that was applied.

SOLUTION

You need to parse the value back to a numeric type by utilizing the ElementExporting event.

Here is a small sample code:

Example 1: Handling the ElementExporting event:

private void clubsGrid_ElementExporting(object sender, GridViewElementExportingEventArgs e)
{
    if (e.Element == ExportElement.Cell)
    {
        var column = e.Context as GridViewDataColumn;
        if (column.Header.ToString() == "My String Column")
        {
            e.Value = string.Format(@"=T(""{0}"")", e.Value);
        }
    }
}
Private Sub clubsGrid_ElementExporting(sender As Object, e As GridViewElementExportingEventArgs)
    Dim column = TryCast(e.Context, GridViewDataColumn)
    If e.Element = ExportElement.Cell Then
        If column.Header.ToString() = "My String Column" Then
            e.Value = String.Format("=T(""{0}"")", e.Value)
        End If
    End If
End Sub