首页 > 代码库 > PHP导出数据到Excel
PHP导出数据到Excel
<?phpdate_default_timezone_set(‘PRC‘);$filename="info.xls";//先定义一个excel文件header("Content-Type: application/vnd.ms-execl");header("Content-Type: application/vnd.ms-excel; charset=utf-8");header("Content-Disposition: attachment; filename=$filename");header("Pragma: no-cache");header("Expires: 0");//我们先在excel输出表头,当然这不是必须的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","root","");mysql_select_db("thinkphp");mysql_query("set names utf8");//在这里我们定义一个名叫studen的表,她有id,name,age,sex四个字段$sql="select id,name,age,sex from student";$result=mysql_query($sql);while($row =mysql_fetch_array($result)){ echo iconv("utf-8", "gb2312", $row[‘id‘])."\t"; echo iconv("utf-8", "gb2312", $row[‘name‘])."\t"; echo iconv("utf-8", "gb2312", $row[‘age‘])."\t"; echo iconv("utf-8", "gb2312", $row[‘sex‘])."\n";}
PHP导出数据到Excel
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。