1

I make from my program an excel file (xls or csv).

I send 00123 and in Excel I see 123

How I can send and see 00123

Thanks in advance

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Gold
  • 57,486
  • 97
  • 211
  • 311
  • 1
    I'm happy to see you're always thanking us in advance - nice and polite. Just as a note: when you do, please use the proper spelling of "Thanks in advance" - there's no apostrophe in that phrase...... – marc_s Dec 07 '10 at 06:37

2 Answers2

3

Its because excel is treating the data as 'numeric'. A simple way to force Excel to accept anything as text is to prepend an apostrophe to the text.

e.g. to write an integer 123 as 00000123 just write:

ActiveCell = "'" & Format(123, "00000000")

EDIT: Another solution is to set the Cells NumberFormatProperty to text:

Worksheet.GetRange(..).EntireColumn.NumberFormat = "@"

You might want to see this article: Excel Cell Auto Format

Aseem Gautam
  • 18,765
  • 11
  • 83
  • 109
2

In C# to see the CSV with the padding use

myVar.PadLeft(5,'0')

In Excel set the number format to custom 00000 or ZipCode

Eric Fortis
  • 14,098
  • 6
  • 38
  • 57