php 查询数据导出伪excel文件
2013-05-22 09:39 freefei 阅读(205) 评论(0) 编辑 收藏 举报
[php]
function export(){
$D_member=M("Member");
$data=$D_member->select();
$output = "<HTML>";
$output .= "<HEAD>";
$output .= "<META http-equiv=Content-Type content=\"text/html; charset=utf-8\">";
$output .= "</HEAD>";
$output .= "<BODY>";
$output .= "<TABLE BORDER=1>";
$output .= "<tr><td>学号</td><td>姓名</td><td>学分</td></tr>";
foreach ($data as $value) {
$output .= "<tr><td>{$value['username']}</td><td>{$value['name']}</td><td>{$value['jf']}</td></tr>";
}
$output .= "</TABLE>";
$output .= "</BODY>";
$output .= "</HTML>";
header("Content-type:application/msexcel");
header("Content-disposition: attachment; filename=output.xls");
header("Cache-control: private");
header("Pragma: private");
print($output);
}
[/php]