How to create an excel spreadsheet?

Reply

Join Date: Dec 2007
Posts: 608
Reputation: OmniX is an unknown quantity at this point 
Solved Threads: 8
OmniX's Avatar
OmniX OmniX is offline Offline
Practically a Master Poster

How to create an excel spreadsheet?

 
0
  #1
Sep 18th, 2009
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:
  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.
"You never stop learning." - OmniX
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC