943,694 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 427
  • PHP RSS
Sep 18th, 2009
0

How to create an excel spreadsheet?

Expand Post »
We have all wanted data to be transfered to excel at one stage or another. I would like to know how people have done it and come to a general consensis on how it should be done. I usually use fopen or simple echo statement and declaring it as .xls or .csv when required. I have found a new error which brings up a NON EXCEL format and a SYLK error (due to me using sessions in the same file I am downloading, which I dont know why it matters). But if I wish to remove both errors as it does not look professional. Also I would like to know the offical content type for both excel formats (.xls and .xlsx). Add your comments and self code so we can get a general consensis!!!

My code:
php Syntax (Toggle Plain Text)
  1. session_start();
  2. $filename = "test.xls";
  3. $ABC = $_SESSION['A']; // Yes a valid session from previous page
  4. $line_1 = "A" . "\t" . "B" . "\t" . "C";
  5. $line_2 = "1" . "\t" . "2" . "\t" . "3";
  6. $line_3 = "HELLO " . $ABC;
  7. $data = $line_1 . "\n" . $line_2 . "\n" . $line_3;
  8. session_destroy();
  9. // What I find a mystery is what is the OFFICAL content type for excel?
  10. header("Content-Type: application/x-msexcel");
  11. header("Content-Disposition: attachment; filename=" . $filename);
  12. echo $data;

Regards, X
Last edited by OmniX; Sep 18th, 2009 at 2:14 am.
Similar Threads
Reputation Points: 31
Solved Threads: 10
Practically a Master Poster
OmniX is offline Offline
652 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: MY PHP MySQL Function keeps returning error message: "Database Query Failed"
Next Thread in PHP Forum Timeline: securing form data





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC