This is a migrated thread and some comments may be shown as answers.

[Solved] Export As String not Int

3 Answers 190 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel Pålsson
Top achievements
Rank 1
Daniel Pålsson asked on 07 Oct 2009, 07:23 AM
Have a grid whit following column:
<telerik:GridBoundColumn DataField="ArticleCode" UniqueName="ArticleCode" HeaderText="ArtikelID" ReadOnly="true" DataType="System.String"></telerik:GridBoundColumn> 

In this column I insert values tha look like "001", "002" etc

But when I export it to Excel it formats the column to Integer values so it only displays 1,2 etc

How do I make the Excel sheet accept the value as a string and not an Integer?

protected void ButtonExportToExcel_Click(object sender, EventArgs e)  
{  
   RadGridMembers.ExportSettings.ExportOnlyData = false;  
   RadGridMembers.ExportSettings.IgnorePaging = true;  
   RadGridMembers.ExportSettings.OpenInNewWindow = true;  
 
   RadGridMembers.Page.Response.ClearHeaders();  
   RadGridMembers.Page.Response.Cache.SetCacheability(HttpCacheability.Private);  
 
   RadGridMembers.MasterTableView.ExportToExcel();  

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 07 Oct 2009, 11:22 AM
Hello Daniel,

Try setting DataFormatString for the column as shown below and see whether it is working fine.

ASPX:
 
<telerik:GridBoundColumn DataField="ArticleCode" UniqueName="ArticleCode" DataFormatString="&nbsp;{0}&nbsp;" HeaderText="ArtikelID" DataType="System.String"
</telerik:GridBoundColumn>  

-Shinu.
0
Daniel Pålsson
Top achievements
Rank 1
answered on 07 Oct 2009, 11:26 AM
Thx Shinu

It worked perfectly!
0
Daniel
Telerik team
answered on 07 Oct 2009, 11:39 AM
Hello Daniel,

Alternative approach could be to use the ExcelExportCellFormatting event  and set the proper style programmatically (using mso-number-format style):

ASP.NET Controls - Grid Forum - Export To Excel Problem

mso-number-format style

ASP.NET Controls - Grid Forum - export money values to Excel

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Daniel Pålsson
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Daniel Pålsson
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or