PHP导出Excel简单实例

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

PHP导出Excel简单实例<?php
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=table.xls");
>
<table border="1">
<tr>
<td>t00</td><td>t01</td><td>t02</td>
</tr>
<tr>
<td>t10</td><td>t11</td><td>t12</td>
</tr>
<tr>
<td>t20</td><td>t21</td><td>t22</td>
</tr>
</table>
只要有则⽂档相当于xls⽂件:
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=table.xls");
需要写⼊了再导出,可参考以下例⼦:
//⽂件写⼊
$files="mei_excel_write.php";
if(!is_writable($files)){ //判断⽂件是否可写
echo"<font color=red>不可写</font>";
}else{
echo"<font color=green>可写</font>";
}
$time=date("Y-m-d H:i:s");
if(isset($_POST['write'])){ //把信息写⼊⽂件
$str="<?php";
$str.="\n";
$str.="header(\"Content-type:application/vnd.ms-excel\");";
$str.="\n";
$str.="header(\"Content-Disposition:attachment;filename=".$time.".xls\");";
$str.="\n";
$str.="?>";
$str.="\n";
$str.="<table border=\"1\">";
$str.="<tr>";
$str.="<td>ID</td>";
$str.=" </tr>";
while ($row = mysql_fetch_array($query)) {
$str.=" <tr>";
$str.="<td>".$st."</td>";
$str.=" </tr>";
}。

相关文档
最新文档