Solved

Writing numbers in text file (csv, excel)

Posted on 2011-03-15
6
1,263 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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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 Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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