php教程 mysql教程如何将数据表转换为Excel输出
$xlsname="倒出信息";
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=$xlsname.xls");
?>
<table>
<tr>
<td ><h3>序号</h3></td>
<td ><h3>内容</h3></td>
<td ><h3>内容</h3></td> </tr></table>
<?
$exapp = new COM("Excel.application") or Die ("Did not connectwww.jzread.com提示你");
$wkb=$exapp->Workbooks->add();
$ex->Application->Visible = 1;
$sheets = $wkb->Worksheets(1); //选择第一个sheet
$sheets->activate; //激活
$sheets->name="Report First page";//更名
//填充单元格
$maxi=20;
$m=1;
for ($i=1;$i<$maxi;$i++) {
for($n=1;$n<5;$n++){
$cell = $sheets->Cells($i,$n) ; #Select the cell (Row Column number)
$cell->activate;
$cell->value = $m;
$m++;
}
}
$ch = $sheets->chartobjects->add(50, 40, 400, 100); #作图
$chartje = $ch->chart;
$chartje->activate;
$chartje->ChartType=63;
$selected = $sheets->range("E1:E$maxi");
$chartje->setsourcedata($selected);
//存盘
$file_name="D:/test.xls"; //路径
if (file_exists($file_name)) {@unlink($file_name) or die("www.jzread.com提示你:文件已经存在,并无法删除!");}
$wkb->SaveAs($file_name); //save
$exapp->Quit();
unset($exapp);
echo "生成成功!";
//方法三
$a = "帐号,邮箱,性别,宝宝出生日期,省份,真实姓名,邮编,手机,地址 rn";
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);
$Sql = "Select * from oy_use";
$Result = mysql_query($Sql) or die(mysql_error());
while($rs = mysql_fetch_array($Result) ){
// if(get_days($rs['m_time'])<= $Table ){
$a.=$rs['User_Name'].','. $rs['User_Mail'].",".($rs['User_Baby_Sex']?'男':'女').",". $rs['User_Baby_Birth'].",";
$a.="".$rs['sheng'].",". $rs['User_rname'].",".$rs['User_Zip'].",".$rs['User_Hand'].",".$rs['User_Address']." rn ";
// }
}
echo $a;/*
第一种方法是最简单的要header("Content-Disposition:filename=$xlsname.xls"); 输出就行了。
第二种复杂但是比较高度,功能就更多了。
第三种就是把数据以cvs格式输出。