php7.27: export excel from mysql
2018-08-10 11:24:27来源:博客园 阅读 ()
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 = "\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>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- PHPExcel如何读取Excel文件 2020-03-10
- php导出excel格式数据问题 2020-02-21
- 详解PHP实现实时生成并下载超大数据量的EXCEL文件 2019-12-15
- php之导出数据到excel时数字变为科学计数的方法 2019-10-17
- php生成excel文件的简单方法 2019-08-09
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash