PHP導(dǎo)出帶樣式的Excel示例代碼
更新時間:2016年08月28日 10:28:50 投稿:daisy
相信大家在工作的時候有客戶會向你抱怨,軟件為他們導(dǎo)出的Excel格式太難看了,這個時候我們就需要到處自定義樣式的Excel了,那么或許這篇文章會對你有所幫助,有需要的可以參考借鑒。
前言
在大家工作中做導(dǎo)出的時候,需要導(dǎo)出自定義的表格或嫌棄導(dǎo)出的Excel格式太難看了。這時候就需要設(shè)置顏色、字號大小、加粗、合并單元格等等。這篇文章通過實例告訴大家怎么做,下面來一起看看。
先來看看效果圖:
實例代碼
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ù),自己進行模板賦值。 $this->display(); }
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>
以上就是本文的全部內(nèi)容,本文通過實例介紹的非常詳細,希望對大家的學(xué)習(xí)和工作能有所幫助,如果有疑問可以留言,謝謝大家對腳本之家的支持。
相關(guān)文章
LotusPhp筆記之:基于ObjectUtil組件的使用分析
學(xué)習(xí)要先易后難,好吧,我剛開始學(xué)習(xí)LotusPhp的時候,就是從最容易的Logger和ObjectUtil開始的,這2個組件基本沒有什么難度。一看就會2013-05-05PHP環(huán)境搭建(php+Apache+mysql)
這篇文章主要為大家詳細介紹了PHP環(huán)境搭建,包括php、Apache、mysql環(huán)境安裝,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11