Solved

Writing numbers in text file (csv, excel)

Posted on 2011-03-15
6
1,257 Views
Last Modified: 2013-12-17
Hello,

I'm writing some data into a text file as *.csv and one of the columns is credit card number. However, when it is opened in Excel its values is converted to scientific notation such as 4.54111E+15  (of course that is due to the format Excel assigns to cell containing this value) however, when I open it notepad or any ascii editor the value is normal.

How can I make it such that when Excel reads it still reads it as a normal number or string?

I tried:


sb.Append(String.Format("\"{0}\"", sCcNum.ToString() )

yet it still Excel shows it with scientific notation.

Thanks.
0
Comment
Question by:akohan
6 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 125 total points
ID: 35139384
If you aren't doing anything with the number then you could try to preface it with an apostrophe ' symbol.  (I think that is the correct one to force excel to treat it is a string rather than a number for display purposes.)
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35143973
Try this:

sb.Append(String.Format("=\"{0}\"", sCcNum.ToString() )

0
 
LVL 11

Expert Comment

by:Sudhakar Pulivarthi
ID: 35148079
Hi,
The best way for that was ="1234567890123". The = makes the cell a formula, and the quotation marks make the enclosed value an Excel string literal. This will display all the digits, even beyond Excel's numeric precision limit, but the cell (generally) won't be able to be used directly in numeric calculations.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 35148207
Eventually got around to checking it - it is an apostrophe.  See attached pictures
0013.jpg
0014.jpg
0
 

Author Comment

by:akohan
ID: 35148296

Thanks to all.
0
 

Author Closing Comment

by:akohan
ID: 35148303
This helped.
Thank you
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now