I am trying to create an application that extracts some data from a database and then uses some data to create a CSV file to load Excel. The code:
foreach (xOFDocInfo cm in docs) { string s = bi.Agency + "," + cm.BatNbr.Trim() + "," + cm.RefNbr + "," + cm.DocType + "," + cm.OrigDocAmt.ToString() + "," + cm.CreateDate.ToShortDateString(); writer.WriteLine(s); }
"cm.BatNbr" is a 6-character zero padding such as "001234". I want Excel to format this column as text so that I don't lose the zeros in front. I tried some tricks, for example, a single-quote number prefix (apostrophe), but all I get is an apostrophe prefix. If I set the cells to be formatted as text, then remove the apostrophes, I will also lose zeros in front.
I accidentally discovered that if I prefix things with a percent sign, Excel converts the value in the cell to percent, so maybe there is a prefix that I can use to force Excel to accept the value in the cell as text when I load it?
Cyberherbalist
source share