【PHP原生】数据库导出excel

 数据库导出excel

<?php
$filename = "info.xls";
//先定义一个excel文件
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header("Content-Disposition:attachment;filename='{$filename}'");
header("Content-Transfer-Encoding:binary");
//我们先在excel输出表头,当然这不是必须的
echo iconv("utf-8", "gb2312", "姓名") . "\t";
echo iconv("utf-8", "gb2312", "手机") . "\t";
echo iconv("utf-8", "gb2312", "日期") . "\t";
echo iconv("utf-8", "gb2312", "地区") . "\t";
echo iconv("utf-8", "gb2312", "详细区域") . "\t";
echo iconv("utf-8", "gb2312", "预购车型") . "\n";
//注意这个要换行
//这里我们定义一个数据库为datebse 数据库用户名:root 密码为:123456
$conn = mysql_connect("localhost", "gdcarvip88YH", "gdcarvipsH778");
mysql_select_db("gdcarvip888");
//这个是数据库名
//需要加这句,不知道为什么,不然导出的中文乱码,大家在使用的时候,如果utf8乱码,就改为GBK,反正也可以
mysql_query('set names utf8');
//查询的表条件
$sql = "select title,mycall,tqsj,dyx,address,ygcx from 表名";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
    echo iconv("utf-8", "gb2312", $row['title']) . "\t";
    echo iconv("utf-8", "gb2312", $row['mycall']) . "\t";
    echo iconv("utf-8", "gb2312", $row['tqsj']) . "\t";
    echo iconv("utf-8", "gb2312", $row['dyx']) . "\t";
    echo iconv("utf-8", "gb2312", $row['address']) . "\t";
    echo iconv("utf-8", "gb2312", $row['ygcx']) . "\n";
}

 

 

 

 
 
 
 

转载于:https://www.cnblogs.com/php99/p/9796261.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值