0

I am doing export of data from database to Excel. After exporting when opening the csv file, the excel application is autoformating the values in excel.

One my cell contained the value -A1177, but it got converted to zero.

Can any one let me know is there any solution to avoid this or switch off this autoformat in excel.

thanks.

Bhaskar
  • 1,680
  • 7
  • 26
  • 40
  • This is an excel issue. Not an c# one. Your doing the perfect job in porting to excel. May be try to format the excel column to just string type tingy. I forgot exactly what type – Zenwalker Jun 13 '11 at 10:46
  • You could open Excel without clicking the csv-file. Click `Data/Get External Data/From Text/Choose the csv-file`. Then you can ensure that all columns will be in the correct format(`text` when in doubt). http://office.microsoft.com/en-us/excel-help/text-import-wizard-HP010102244.aspx – Tim Schmelter Jun 13 '11 at 10:50

3 Answers3

2

The easiest way to do it, is to simply wrap the value in quotes, e.g. asdasd,"-A1177",11/03/1984 in your CSV file. You can also change the format of the column to `Text'.

Otherwise, check out this excellent Stack Overflow Question and Answer

Community
  • 1
  • 1
Matthew Abbott
  • 60,571
  • 9
  • 104
  • 129
1

Change column Data Format when importing the text change it to Text

DeveloperX
  • 4,633
  • 17
  • 22
0

Insert a ' at the start of any formula in Excel and it will be considered a string.

So if possible, check when generating the CSV file if the first char in a given field can be understood as an Excel formula "opener" (off my mind {=, -, +}) and prepend a '.

You can do it for every field, but its only strictly necessary if the text can be misunderstood as a formula.

InBetween
  • 32,319
  • 3
  • 50
  • 90