有以下提示供参考:
1、你可以直接抓取html表格代码,然后用PHP输出,如以下示例:
function outputXlsHeader($data, $file_name = 'export'){
header('Content-Type: text/xls')
header("Content-type:application/vnd.ms-excelcharset=utf-8")
$str = mb_convert_encoding($file_name, 'gbk', 'utf-8')
header('Content-Disposition: attachmentfilename="' . $str . '.xls"')
header('Cache-Control:must-revalidate,post-check=0,pre-check=0')
header('Expires:0')
header('Pragma:public')
$table_data = '<table border="1">'
foreach ($data as $line) {
$table_data .= '<tr>'
foreach ($line as $key => &$item) {
$item = mb_convert_encoding($item, 'gbk', 'utf-8')
$table_data .= '<td>' . $item . '</td>'
}
$table_data .= '</tr>'
}
$table_data .= '</table>'
echo $table_data
die()
}
2、先抓取 Html 表格,再用 PhpExcel 类库进行 Excel 表格操作。
$result = mysql_query("SELECT * FROM table_name")while($row = mysql_fetch_array($result))
{
echo $row['ID'] . " " . $row['xuehao'] . " " . $row['xingming'] . " " . $row['chengji1'] . " " . $row['chengji2']
echo "<br />"
}
<html><head>
<title>以下是一个最简单的5行6列的HTML的表格页面</title>
</head>
<body>
<table>
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
<tr>
<td></td><td></td><td></td><td></td><td></td><td></td>
</tr>
</table>
</body>
</html>