php7.27: export excel from mysql

來源:互聯網
上載者:User

標籤:int   develop   github   developer   isp   schema   geo   har   echo   

https://stackoverflow.com/questions/15699301/export-mysql-data-to-excel-in-php

https://github.com/PHPOffice

https://www.ibm.com/developerworks/library/os-phpexcel/index.html

<!doctype html><html><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta charset="utf-8"><title>execl</title><meta name="keywords" content="geovindu"><meta name="description" content="塗聚文"></head><body><?php$servername = "localhost";  //127.0.0.1:3306$username = "root";$password = "8888";$dbname = "sakila";//mysql and db connection$con = new mysqli($servername, $username, $password, $dbname);if ($con->connect_error) {  //error check    die("Connection failed: " . $con->connect_error);}else{}$DB_TBLName = "dt_sample"; $filename = "geovindu";  //your_file_name$file_ending = "utf-8";   //file_extentionheader("Content-Type: application/vnd.ms-excel;charset=utf-8");//header("Content-Type: application/xls");  //header("Content-type: application/octet-stream");header("Content-Disposition: attachment; filename=$filename.xls");  header("Pragma: no-cache"); header("Expires: 0");$sep = "\t";$sql="SELECT * FROM dt_sample"; $resultt = $con->query($sql);print("<table><tr>"); while ($property = mysqli_fetch_field($resultt)) { //fetch table field name    echo "<td>".$property->name."</td>";}print("</tr>");   while($row = mysqli_fetch_row($resultt))  //fetch_table_data{print("<tr>");    $schema_insert = "";    for($j=0; $j< mysqli_num_fields($resultt);$j++)    {        if(!isset($row[$j]))            $schema_insert .="<td>". "NULL".$sep."</td>";        elseif ($row[$j] != "")            $schema_insert .="<td>"."$row[$j]".$sep."</td>";        else            $schema_insert .= "<td>".$sep."</td>";    }    $schema_insert = str_replace($sep."$", "", $schema_insert);    $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);    //$schema_insert .= "</tr>";    print(trim($schema_insert));    print("</tr>");}print "</table>";?></body></html>

  

php7.27: export excel from mysql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.