php output to excel, long numbers converted

I have a php page that outputs to excel.
It pretty much is a dump of a form.
When I print to the screen, without the following lines

 header('Content-type: application/csv');
 header('Content-Disposition: attachment; filename="' . date("F_j_Y_g_i_a") . '.csv"');

Everything is as it should be.

When I add those lines, if I have the number 012345678901234567890, excel converts
it to 1.23457E+19 as soon as I open it.  If I try to convert it to a number, once in excel,
it drops some numbers, it goes to 12345678901234500000.00

How do I prevent excel from formatting this string.
I don't specify any sort of number at all, I just print out with tabs and "\n"


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In a CSV file you have no control over formatting. Excel is going to format it in the default fashion for your standard spreadsheet template. You can change your defaults (within Excel) or you can code some VBA to start Excel, change the defaults, and then load the CVS, but that's about it.
jackjohnson44Author Commented:
So it is impossible to output the number 012345678901234567890 from a webpage into a csv file?

I put single quotes around the number and it did not format it.
I would like to remove them however.
It's possible to output it, but Excel will not preserve the full number -- as you have seen, it only keeps 15 digits, and then chops off the rest.

If you quote it, excel will treat it as a string and not truncate it. But as soon as you try to do math on it, the value gets truncated.

PHP is better at math than Excel. :(


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.