PHP導(dǎo)出帶樣式的Excel示例代碼
前言
在大家工作中做導(dǎo)出的時(shí)候,需要導(dǎo)出自定義的表格或嫌棄導(dǎo)出的Excel格式太難看了。這時(shí)候就需要設(shè)置顏色、字號(hào)大小、加粗、合并單元格等等。這篇文章通過(guò)實(shí)例告訴大家怎么做,下面來(lái)一起看看。
先來(lái)看看效果圖:
實(shí)例代碼
PHP代碼:
/** * 導(dǎo)出文件 * @return string */ public function export() { $file_name = "成績(jī)單-".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(); }
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>成績(jī)單</h2> </td> </tr> <tr> <td style='width:54pt' align="center">編號(hào)</td> <td style='width:54pt' align="center">姓名</td> <td style='width:54pt' align="center">語(yǔ)文</td> <td style='width:54pt' align="center">數(shù)學(xué)</td> <td style='width:54pt' align="center">英語(yǔ)</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>
以上就是本文的全部?jī)?nèi)容,本文通過(guò)實(shí)例介紹的非常詳細(xì),希望對(duì)大家的學(xué)習(xí)和工作能有所幫助,如果有疑問(wèn)可以留言,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
LotusPhp筆記之:基于ObjectUtil組件的使用分析
學(xué)習(xí)要先易后難,好吧,我剛開(kāi)始學(xué)習(xí)LotusPhp的時(shí)候,就是從最容易的Logger和ObjectUtil開(kāi)始的,這2個(gè)組件基本沒(méi)有什么難度。一看就會(huì)2013-05-05PHP環(huán)境搭建(php+Apache+mysql)
這篇文章主要為大家詳細(xì)介紹了PHP環(huán)境搭建,包括php、Apache、mysql環(huán)境安裝,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11實(shí)例分析基于PHP微信網(wǎng)頁(yè)獲取用戶信息
本篇內(nèi)容主要給大家詳細(xì)分析了用PHP制作微信網(wǎng)頁(yè)來(lái)獲取用戶基本信息的過(guò)程,以及步驟講解。2017-11-11