• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 489
  • Last Modified:

php output to excel, long numbers converted

Hi,
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"

Thanks

0
jackjohnson44
Asked:
jackjohnson44
  • 2
1 Solution
 
Austin_HastingsCommented:
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.
0
 
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.
0
 
Austin_HastingsCommented:
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. :(

=Austin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now