New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Treat values as Text when Exporting to Excel
DESCRIPTION
Set the DataFormatString property of the GridColumn
to make RadGrid specify the cell data type as Text.
When exporting to Excel, RadGrid will set the Excel's Cell value according to the original values. However, Microsoft Office Excel has a smart functionality that will automatically treat values as different Data types when the Excel document is opened.
String values that contain only numbers will be treated as the respective Type.
Scenarios:
- String values containing only numbers "001" will loose their leading zeroes resulting in "1" in the excel.
- String values containing a few pairs of numbers e.g. "01 01 05" they may be treated as Dates "01/01/2005" in excel.
SOLUTION
To ensure that the String values will be treated as Text, set the DataFormatString property of the GridColumn
to {0:@}, where the @ sign will indicate that the value is of type text.
ASP.NET
<telerik:GridBoundColumn DataFormatString="{0:@}">