Find the answer to your Linux question:
Results 1 to 2 of 2
Hi all, I'm exporting data to excel file in php,but the data starts at middle of excel sheet. How to correct this? Here is sample code with i used, Code: ...
  1. #1
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Question php + download excel

    Hi all,
    I'm exporting data to excel file in php,but the data starts at middle of excel sheet.
    How to correct this?
    Here is sample code with i used,
    Code:
    $header = "Number  \t Color \tSize ";
    $filename="product";
    //Fetch data and assign to $data
    $data = "a";
    $data .= "b";
    //sent the data to browser 
    header("Content-type: application/x-msdownload");
    		header("Content-Disposition: attachment; filename=" . $filename . ".xls");
    		header("Pragma: no-cache");
    		header("Expires: 0");
    		print "\n$header";
    		print "\n$data";
    Thanks
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    i found this at google.....now excel files contents comes at second line ...(that's huge improvement .....
    Code:
        ob_end_clean();
       ini_set('zlib.output_compression','Off');
        header('Pragma: public');
       // header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");                  // Date in the past   
      //  header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
     	 header('Cache-Control: no-store, no-cache, must-revalidate');     // HTTP/1.1
     	header('Cache-Control: pre-check=0, post-check=0, max-age=0');    // HTTP/1.1
      //  header ("Pragma: no-cache");
        header("Expires: 0");
        header('Content-Transfer-Encoding: none');
        header('Content-Type: application/vnd.ms-excel;');                 // This should work for IE & Opera
        header("Content-type: application/x-msexcel");                    // This should work for the rest
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...