PHP導(dǎo)出帶樣式的Excel

工作中做導(dǎo)出的時候,需要導(dǎo)出自定義的表格或嫌棄導(dǎo)出的Excel格式太難看了。
需要設(shè)置顏色、字號大小、加粗、合并單元格等等。

效果圖:

PHP導(dǎo)出帶樣式的Excel

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>

Thanks ~

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 工作中做導(dǎo)出的時候,需要導(dǎo)出自定義的表格或嫌棄導(dǎo)出的Excel格式太難看了。需要設(shè)置顏色、字號大小、加粗、合并單元...
    我能忍受多少閱讀 769評論 0 0
  • 工作中做導(dǎo)出的時候,需要導(dǎo)出自定義的表格或嫌棄導(dǎo)出的Excel格式太難看了。需要設(shè)置顏色、字號大小、加粗、合并單元...
    新亮筆記閱讀 7,219評論 4 1
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,119評論 25 708
  • Aboutjxl is a pure java 5 super-project that includes Enc...
    CoderZS閱讀 20,073評論 8 17
  • 天黑了 我念起昨天你家的那只貓 不見了 你喊它回來 不見影 你都傷心了 它不回來
    一棵碩大的樹閱讀 225評論 3 3

友情鏈接更多精彩內(nèi)容