工作中做導(dǎo)出的時候,需要導(dǎo)出自定義的表格或嫌棄導(dǎo)出的Excel格式太難看了。
需要設(shè)置顏色潦刃、字號大小、加粗胧洒、合并單元格等等略荡。
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/1817494-93cf636e55cd20f0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
PHP代碼:
``php
/**
- 導(dǎo)出文件
- @return string
*/
public function export()
{
$file_name = "成績單-".date("Y-m-d H:i:s",time());
$file_suffix = "xls";
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file_name.$file_suffix");
//根據(jù)業(yè)務(wù)通今,自己進(jìn)行模板賦值辫塌。
$this->display();
}
``php
HTML代碼:
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
</head>
<body>
<table border=1 cellpadding=0 cellspacing=0 width="100%" >
<tr>
<td colspan="5" align="center">
<h2>成績單</h2>
</td>
</tr>
<tr>
<td style='width:54pt' align="center">編號</td>
<td style='width:54pt' align="center">姓名</td>
<td style='width:54pt' align="center">語文</td>
<td style='width:54pt' align="center">數(shù)學(xué)</td>
<td style='width:54pt' align="center">英語</td>
</tr>
<tr>
<td align="center">1</td>
<td style="background-color: #00CC00;" align="center">Jone</td>
<td style="background-color: #00adee;" align="center">90</td>
<td style="background-color: #00CC00;" align="center">85</td>
<td style="background-color: #00adee;" align="center">100</td>
</tr>
<tr>
<td align="center">2</td>
<td style="background-color: #00CC00;" align="center">Tom</td>
<td style="background-color: #00adee;" align="center">99</td>
<td style="background-color: #00CC00;" align="center">85</td>
<td style="background-color: #00adee;" align="center">80</td>
</tr>
</table>
</body>
</html>