Format String Values as Numbers in HTML Export
PROBLEM
When exporting a RadGridView to Excel using ExportFormat.HTML, the string values that can be converted to numbers, are opened in Excel as numbers.
This behavior does not occur when exporting using ExportFormat.ExcelML.
CAUSE
When using the HTML format, the RadGridView actually saves data in an Excel readable html format.
SOLUTION
You will need to format the exported string column appropriately so that the Excel file interprets it as a string.
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