<?php
$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","password");
mysql_select_db("$datebase");
mysql_query("set names utf8");
//在这里我们定义一个名叫studen的表,她有id,name,age,sex四个字段
$sql="select * from node";
$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";
}
?>
简单的导出EXCEL并下载
最新推荐文章于 2024-06-04 13:24:55 发布