一个php文件就可以把数据库的数据导出Excel表格
数据库内容太多,复制粘贴太麻烦?
那就用代码实现把,把代码写好了,导出还不容易吗,访问即可导出。
excel.php
<?php error_reporting(E_ALL ^ E_DEPRECATED); $localhost = '数据库地址'; $dbname = '数据库名'; $dbuser = '数据库账号'; $dbpwd = '数据库密码'; $tbname = "需要导出的数据库表名"; ob_end_clean(); header('Content-type: text/html; charset=utf-8'); header("Content-type:application/vnd.ms-excel;charset=UTF-8"); header("Content-Disposition:filename=data.xls");// 文件名自己改,默认data.xls $conn = mysql_connect($localhost,$dbuser,$dbpwd) or die("连接数据库失败"); mysql_select_db($dbname, $conn); mysql_query("set names 'UTF-8'"); $result=mysql_query("SELECT * FROM $tbname"); echo "<table>"; echo "<tr>"; echo "<th>A1单元格</th>"; echo "<th>B1单元格</th>"; echo "<th>C1单元格</th>"; echo "<th>D1单元格</th>"; echo "</tr>"; echo "</table>"; while($row=mysql_fetch_array($result)){ //下面data改成你自己数据库对应的字段 $data1 = $row["data1"]; $data2 = $row["data2"]; $data3 = $row["data3"]; $data4 = $row["data4"]; //输出字段的数据到单元格 //下面data改成你自己数据库对应的字段 echo "<table>"; echo "<tr>"; echo "<td>$data1</td>"; echo "<td>$data2</td>"; echo "<td>$data3</td>"; echo "<td>$data4</td>"; echo "</tr>"; echo "</table>"; } ?>
然后访问excel.php就可以弹出表格下载了。
作者:TANKING
网站:likeyunba.com
微信:likeyunba520
相关推荐
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23