When exporting at work, I need to export a customized table or I feel that the exported Excel format is too ugly.
You need to set color, font size, bold, merge cells, etc.
效果图:
PHP代码:/**<br>
*Export file<br>
* @return string<br>
*/<br>
public function export()<br>
{<br>
$file_name = "成绩单-".date("Y-m-d H:i:s",time());<br>
$file_suffix = "xls";<br>
header("Content-Type: application/vnd.ms-excel");<br>
header("Content-Disposition: attachment; filename=$file_name.$file_suffix");<br>
//根据业务,自己进行模板赋值。<br>
$this->display();<br>
}
HTML代码:<html xmlns:o="urn:schemas-microsoft-com:office:office"<br />
xmlns:x="urn:schemas-microsoft-com:office:excel"<br />
xmlns="http://www.w3.org/TR/REC-html40"><br>
<br>
<head><br>
<meta http-equiv=Content-Type content="text/html; charset=utf-8"><br>
<meta name=ProgId content=Excel.Sheet><br>
<meta name=Generator content="Microsoft Excel 11"><br>
</head><br>
<br>
<body><br>
<table border=1 cellpadding=0 cellspacing=0 width="100%" ><br>
<tr><br>
<td colspan="5" align="center"><br>
<h2>成绩单</h2><br>
</td><br>
</tr><br>
<tr><br>
<td style='width:54pt' align="center">编号</td><br>
<td style='width:54pt' align="center">姓名</td><br>
<td style='width:54pt' align="center">语文</td><br>
<td style='width:54pt' align="center">数学</td><br>
<td style='width:54pt' align="center">英语</td><br>
</tr><br>
<br>
<tr><br>
<td align="center">1</td><br>
<td style="background-color: #00CC00;" align="center">Jone</td><br>
<td style="background-color: #00adee;" align="center">90</td><br>
<td style="background-color: #00CC00;" align="center">85</td><br>
<td style="background-color: #00adee;" align="center">100</td><br>
</tr><br>
<br>
<tr><br>
<td align="center">2</td><br>
<td style="background-color: #00CC00;" align="center">Tom</td><br>
<td style="background-color: #00adee;" align="center">99</td><br>
<td style="background-color: #00CC00;" align="center">85</td><br>
<td style="background-color: #00adee;" align="center">80</td><br>
</tr><br>
<br>
</table><br></body><br>
</html>
Thanks ~
Source: http://mp.weixin.qq.com/s?__biz=MjM5NDM4MDIwNw==&mid=2448834670&idx=1&sn=1cccfd60a7227972958d75f3d775c669#rd
For more [dry information sharing], please follow my personal subscription account.