Heim >Backend-Entwicklung >PHP-Tutorial >php导出csv或xls文件程序_PHP教程
由于工作需要今天我们要把mysql数据库里面的数据导出到execel里面用,后来在网上找了一下原来这么简单,因csv文件只要以"," 分开就OK了,下面我们就来看看实例吧.
include("../inc/connect.php");
$Date = date("Y-m-d");
$Filename = $Date.".csv";
$Table = isset($_GET['tid'])?$_GET['tid']:'';
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);
echo "用户名,真实姓名,联系方式,联系QQ,联系地址,邮箱地址 rn";
$Sql = "Select * from gx_member where datediff(m_time,'".date("Y-m-d H:i:s")."')
$Result = mysql_query($Sql);
while($rs = mysql_fetch_array($Result) ){
echo $rs['m_name'].','. $rs['m_realname'].",". $rs['m_tel'].",". $rs['m_qq'].",". $rs['m_address'].",". $rs['m_mail']." rn ";
}
?>
上面我们用的是导出csv文件还有一种就导出xls文件只要修改一下
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);
就差不多了.
本站原创转载请注明www.111cn.cn/phper/php.html