如何利用php导出excel数据表
2018-10-14 站长 站长日志
利用php导出excel数据表代码
<?
Header("Content-type:application/octet-stream");
Header("Accept-Ranges:bytes");
Header("Content-type:application/vnd.ms-excel");
Header("Content-Disposition:attachment;filename=test.xls");
$con = mysql_connect("localhost","数据库登陆名","数据库密码");
mysql_select_db("数据库名");
mysql_query('set names utf8');//数据库编码
$sql = "select
$result = mysql_query($sql,$con);
echo "id\tusername";//输出的excel的列名,用\t换列
while ($rs=mysql_fetch_array($result)){
}
?>
例子:
<?php
Header("Content-type:application/octet-stream");
Header("Accept-Ranges:bytes");
Header("Content-type:application/vnd.ms-excel");
Header("Content-Disposition:attachment;filename=test.xls");
$con = mysql_connect("localhost","root","123456");
mysql_select_db("db_test");
mysql_query('set names utf8');
$sql = "select id,FirstName,LastName,Age,Hometown,Job from user";
$result = mysql_query($sql,$con);
echo "id\tFirstName\tLastName\tAge\tHometown\tJob";
while ($rs=mysql_fetch_array($result)){
}
?>
下一篇:帝国CMS会员空间伪静态规则