<?php
$filename="info.xls";//先定義一個(gè)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輸出表頭,,當(dāng)然這不是必須的
echo iconv("utf-8", "gb2312", "編號(hào)")."\t";
echo iconv("utf-8", "gb2312", "姓名")."\t";
echo iconv("utf-8", "gb2312", "年齡")."\t";
echo iconv("utf-8", "gb2312", "性別")."\n";//注意這個(gè)要換行
//這里我們定義一個(gè)數(shù)據(jù)庫(kù)為datebse 數(shù)據(jù)庫(kù)用戶名:root 密碼為:123456
$conn = mysql_connect("localhost","root","123456");
mysql_select_db("datebse");
//在這里我們定義一個(gè)名叫studen的表,,她有id,,name,,age,sex四個(gè)字段
$sql="select id,name,age,sex from studen";
$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";