Solved

Writing numbers in text file (csv, excel)

Posted on 2011-03-15
6
1,266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…

734 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