動態生成的DOM不會觸發onclick事件的原因及解決方法
637
2024-02-22
前言
在大家工作中做導出的時候,需要導出自定義的表格或嫌棄導出的Excel格式太難看了。這時候就需要設置顏色、字號大小、加粗、合并單元格等等。這篇文章通過實例告訴大家怎么做,下面來一起看看。
先來看看效果圖:
實例代碼
PHP代碼:
/** * 導出文件 * @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"); //根據業務,自己進行模板賦值。 $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">數學</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>
以上就是本文的全部內容,本文通過實例介紹的非常詳細,希望對大家的學習和工作能有所幫助,如果有疑問可以留言,謝謝大家對綠夏網的支持。
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!