export data to xls format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sejal17
    New Member
    • Dec 2007
    • 56

    export data to xls format

    Dear Sir,
    Can you tell me how to export data from MySQL database to a xls file using php code?I have to export data from different tables of mysql database to a single xls file.Please help me!!!

    Regards,
    Sejal Mandaliya
  • zabsmarty
    New Member
    • Feb 2007
    • 25

    #2
    Hello Sejal Mandaliya,
    I send you the script that make your work easy....

    Reply me hows its worked.


    Regards
    zabsmarty


    Code:
    <?php
    //include db connection file
    
    include 'connection.php';
    
    $query = "SELECT first_name, last_name, preferred_name, nick_name, ethnicity, gender, email, mobile, phone, line_1,line_2, subrub, city,country, graduating_university, year_graduation, level_training, level_training_year, hospital_main, vocational_interest_1 FROM members ";
    
    $result = mysql_query($query) or die('Error, query failed');
    
    $tsv = array();
    $html = array();
    while($row = mysql_fetch_array($result, MYSQL_NUM))
    {
    	$tsv[]  = implode("\t", $row);
    	$html[] = "<tr><td>" .implode("</td><td>", $row) . "</td></tr>";
    }
    
    $tsv  = implode("\r\n", $tsv);
    $html = "<table>" . implode("\r\n", $html) . "</table>";
    
    $fileName = date("d-m-Y").'_mysql.xls';
    header("Content-type: application/vnd.ms-excel"); 
    header("Content-Disposition: attachment; filename=$fileName");
    
    //echo $tsv;
    echo $html;
    
    //include 'library/closedb.php';
    header('location:thanks.php');
    ?>


    Originally posted by sejal17
    Dear Sir,
    Can you tell me how to export data from MySQL database to a xls file using php code?I have to export data from different tables of mysql database to a single xls file.Please help me!!!

    Regards,
    Sejal Mandaliya

    Comment

    • sejal17
      New Member
      • Dec 2007
      • 56

      #3
      Thanks,
      Thank you very very much.Your code is working properly.But the lines are not enalbed in xls file.Data is displayed properly but the lines are not enabled in xls file.

      Comment

      • zabsmarty
        New Member
        • Feb 2007
        • 25

        #4
        Thanks to reply, and no problem for thanks, Sejal i does not understand this problem please clarify me so i make to solve this problem for you. reply me soon.

        Ragards
        zabmsarty



        Originally posted by sejal17
        Thanks,
        Thank you very very much.Your code is working properly.But the lines are not enalbed in xls file.Data is displayed properly but the lines are not enabled in xls file.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Sejal.

          Check out the Spreadsheet_Exc el_Writer class.

          Comment

          Working...