1

I need to write some long integer to csv file with C# (vs2010), for example, the number is 33333333333333333, but when I open the csv file with excel, what I see is like this: 3.33333E+16, I don't want this effect, I just want to see the number in text format when open it in Excel.
my code is like below:

var csv = new StringBuilder();
var filePath = "c:\\zzx\\test.csv";

long a = 222222222222222222L;
long b = 33333333333333333L;

var newLine = string.Format("'{0},\"{1}\"", a, b);
csv.AppendLine(newLine);

File.WriteAllText(filePath, csv.ToString());

can anyone help me solve this issue?

Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
user2575502
  • 703
  • 12
  • 28
  • 1
    You cannot control formatting in a CSV, since it's just a plain-text file. You could prepend your number with a single-quote, but then it will be treated as text in Excel. – Tim Williams Oct 12 '16 at 05:51
  • 1
    You might find it instructive to paste that value (17 `3`s) into a cell in Excel, and see what value Excel actually ends up holding... – AakashM Oct 12 '16 at 08:14
  • Possible duplicate of [Excel CSV - Number cell format](http://stackoverflow.com/questions/137359/excel-csv-number-cell-format) – Massimiliano Kraus Dec 01 '16 at 11:19

0 Answers0