1

I am sending a email to prgrom manager and Attaching all the details filled by the applicant in a csv. when they receive the email they are missing a 0 in the Zipcode.

I am using C# and asp.net I placed a break point just before I write data into CSV and It is looking good with the 0. But when I receive the email and open the Excel When I look at Zipcode it is missing the 0.

Can anyone suggest me how to correct this issue?

Thanks

SmilingLily
  • 333
  • 1
  • 5
  • 17
  • The problem is that Excel 'helpfully' converts a digit-string into a number. And a number has no leading 0's. See also http://stackoverflow.com/q/137359/121309 – Hans Kesting Oct 21 '11 at 14:08

3 Answers3

1

Append a ' symbol in front of your numbers (a @ in the excel code itself):

C# : string zip = @"0066222";

Excel: `0066222

Excel will read it as text and preserve the format rather than a number (where it trims the leading 0's).

KreepN
  • 8,528
  • 1
  • 40
  • 58
  • The quote doesn't work from within a .csv. You don't need that `@` in the C# code in this case. `string zip = "0066222";` gives the exact same value to the variable. – Hans Kesting Oct 21 '11 at 14:42
1

The data will need formatted like this: ="001",="002",="003"

UnhandledExcepSean
  • 12,504
  • 2
  • 35
  • 51
0

Append a single quote character (') to the beginning of the zip code value before you write it to the Excel file. This will tell Excel to show the exact value in that field. Otherwise, Excel will interpret that field as being numeric, and trim leading zeroes.

Tim S. Van Haren
  • 8,861
  • 2
  • 30
  • 34