zoukankan      html  css  js  c++  java
  • php7.27: export excel from mysql

    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_extention
    header("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 = "	";
    
    $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("/
    |
    
    |
    |
    /", " ", $schema_insert);
        //$schema_insert .= "</tr>";
        print(trim($schema_insert));
        print("</tr>");
    }	
    print "</table>";	
    ?>
    </body>
    </html>
    

      

  • 相关阅读:
    poj 3616 Milking Time
    poj 3176 Cow Bowling
    poj 2229 Sumsets
    poj 2385 Apple Catching
    poj 3280 Cheapest Palindrome
    hdu 1530 Maximum Clique
    hdu 1102 Constructing Roads
    codeforces 592B The Monster and the Squirrel
    CDOJ 1221 Ancient Go
    hdu 1151 Air Raid(二分图最小路径覆盖)
  • 原文地址:https://www.cnblogs.com/geovindu/p/9455783.html
Copyright © 2011-2022 走看看