Karthik K

Karthik K

  • 1.2k
  • 429
  • 44.9k

Excel Export string column in asp.net ?

Feb 23 2020 11:50 PM
Hi All ,
 
I have issue on Excel Export. While I do have String Coulmn in database but which contains Number. While I export.its how some other formats.
 
8.00318E+12
 
How can I resolve this issue? I can show the code too. If anyone knows just suggest me with example.
 
The following code i just used in Excel Export ..
  1. //Create a dummy GridView  
  2. GridView GridView1 = new GridView();  
  3. GridView1.ShowFooter = true;  
  4. GridView1.AllowPaging = false;  
  5. GridView1.DataSource = Dt2;  
  6. GridView1.DataBind();  
  7. Response.Clear();  
  8. Response.Buffer = true;  
  9. Response.AddHeader("content-disposition",  
  10. "attachment;filename=MemberHistory.xls");  
  11. Response.Charset = "";  
  12. Response.ContentType = "application/vnd.ms-excel";  
  13. StringWriter sw = new StringWriter();  
  14. HtmlTextWriter hw = new HtmlTextWriter(sw);  
  15. for (int i = 0; i < GridView1.Rows.Count; i++)  
  16. {  
  17. //Apply text style to each Row  
  18. GridView1.Rows[i].Attributes.Add("class""textmode");  
  19. }  
  20. GridView1.RenderControl(hw);  
  21. //style to format numbers to string  
  22. string style = @"<style> textmode { mso-number-format:General } </style>";  
  23. Response.Write(style);  
  24. Response.Output.Write(sw.ToString());  
  25. Response.Flush();  
  26. Response.End();  
Thanks in Advance
Karthik K

Answers (2)