asp.net - C# exporting csv with incorrect column format (Excel) -
I am exporting gridview data in a CSV file, one of the columns contains a coupon number which is 18 Points long, non floating point The number needs to be displayed in the Excel form of its full number as Here is my export code: You can wrap each value in such a way: for example For: Obviously this CSV file Not very good at, but it imports in Excel like yours. CSV file when I open the CSV file in Excel , for example , 720137994699937608 and others are shown as:
Then when I change the column size or change the column type for the number, the coupon number displayed in this form Is given:
You will see that Excel has been changed, coupon number in a floating point number and now the number within the coupon number has been changed with zero in the end. that's horrible.
Secure void btnExport_Click (Object Sender, EventArgs e) {Response.Clear (); reaction. Buffer = true; Response.AddHeader ("Content-Properties", "Attachment; File Name = All Prizes.csv Reports"); Response. Charset = ""; Response.ContentType = "csv"; Stringbilder sb = new stringbiller (); Sb.Append ("First name" + ','); Sb.Append ("Last name" + ','); Sb.Append ("CouponNumber" + ','); String [] splitColumns = sb.ToString (). Split (new four [] {','}); // Add new line sb.Append ("\ r \ n"); {Fore string (string column in split column) {if (column == "Firstname") {// Capitolize first letter string first = (for example, Globals Released HTML (GVRPortsAlPrice.ROS [I] .Cell [1] .text.Rim ()); If (string.IsNullOrEmpty (first)) {first = ""; } If (! String.isnaloractic (first)) {first = first. Kolavar (); // Convert lowercase before the first letter upper part first = "\" "+ first.first (first). ToString (). ToUpper () + string .Join (" ", first. Skip (1)) +" \ ""; } Sb.Append (first + ','); } Else if (column == "LastName") {// Capitals first letter string last = globals. Released HTML (GVRPortsAllripz.ROS [Ii] .Cell [2] .text.Rim ()); If (string.IsNullOrEmpty (last)) {end = ""; } If (! String.IsNullOrEmpty (last)) {end = last. ToLower (); // Convert lowercase before the upper part of the first letter. Final = "\" "+ last. First (first) .toasting (.) Touper () + string .join (" ", last. Skip (1)) +" \ ""; } Sb.Append (Last + ','); } And if (column == "couponnumber") {string cn = globals Replay HTML (GVRPortsAllyPrice.ROS [Ii] .Cell [8] .text.Rim ()); If (string.IsNullOrEmpty (cn)) {cn = ""; } If (! String.isnaloractic (cn)) {sb.Append ("\" "+ cn +" \ "" + ','); } Other {sb.Append (cn + ','); }}} // Attach the new line sb.Append ("\ r \ n"); } Response.Output.Write (sb.ToString ()); Response.Flush (); Response.End (); } Change the public static string HTML (string string) {strInput = strInput.Replace ("& amp; quot;", "\" "+" \ ""); StrInput = strInput.Replace ("& amp; amp;", "& amp;"); StrInput = strInput.Replace ("& amp; nbsp;", string.Empty); StrInput = strInput.Replace ("'", "'"); Return Strinput Replay ("& amp; # 39;", "'") Trim ();
" = "" Data here "" "
column1, column2 "=" "1231231231231323121321" "," = "" 123 ""
Comments
Post a Comment