微擎框架之——精簡版導出excel表-Poison

多說廢話無用,代碼纔是王道!

PHP端:

//查出需要導出的內容

 

$data = pdo_fetchall("SELECT * FROM ".tablename('come_orderpft'));

 

//進入下載頁面
		include $this->template('download');


前端頁面:

 

這段網上的php原生代碼,我把他改造成 了微擎可用的導出

 

{php echo header('Content-type: application/vnd.ms-excel');}
{php echo header('Content-Disposition: attachment; filename="維修記錄表.xls"');}
<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=utf8">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 12">
<link rel=File-List href="comm.files/filelist.xml">
<style id="comm_32218_Styles">
<!--table
	{mso-displayed-decimal-separator:"\.";
	mso-displayed-thousand-separator:"\,";}
.font532218
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋體;
	mso-generic-font-family:auto;
	mso-font-charset:134;}
.xl1532218
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:black;
	font-size:11.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋體;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
.xl6332218
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:black;
	font-size:11.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋體;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:center;
	vertical-align:middle;
	border:.5pt solid windowtext;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
.xl6432218
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:black;
	font-size:11.0pt;
	font-weight:700;
	font-style:normal;
	text-decoration:none;
	font-family:宋體;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:center;
	vertical-align:middle;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
.xl6532218
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:black;
	font-size:11.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋體;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:center;
	vertical-align:middle;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
.xl6632218
	{padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:black;
	font-size:11.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋體;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:center;
	vertical-align:middle;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;
	mso-background-source:auto;
	mso-pattern:auto;
	white-space:nowrap;}
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋體;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-char-type:none;}
-->
</style>
</head>

<body>
<!--[if !excel]>  <![endif]-->
<!--下列信息由 Microsoft Office Excel 的“發佈爲網頁”嚮導生成。-->
<!--如果同一條目從 Excel 中重新發布,則所有位於 DIV 標記之間的信息均將被替換。-->
<!----------------------------->
<!--“從 EXCEL 發佈網頁”嚮導開始-->
<!----------------------------->

<div id="comm_32218" align=center x:publishsource="Excel">


<table border=0 cellpadding=0 cellspacing=0 width=300 style='border-collapse:
 collapse;table-layout:fixed;width:233pt'>
 <col width=72 span=3 style='width:54pt'>
 <col width=94 style='mso-width-source:userset;mso-width-alt:3008;width:71pt'>
 <tr height=18 style='height:13.5pt'>
  <td height=18 class=xl6332218 style='height:13.5pt;border-top:none'>訂單編號</td>
  <td class=xl6332218 style='border-top:none;border-left:none'>維修人員</td>
  <td class=xl6332218 style='border-top:none;border-left:none'>用戶名稱</td>
  <td class=xl6332218 style='border-top:none;border-left:none'>手機號碼</td>
  <td class=xl6332218 style='border-top:none;border-left:none'>機器類型</td>
  <td class=xl6332218 style='border-top:none;border-left:none'>維修類型</td>
  <td class=xl6332218 style='border-top:none;border-left:none'>下單時間</td>
   <td class=xl6332218 style='border-top:none;border-left:none'>維修價格</td>
   <td class=xl6332218 style='border-top:none;border-left:none'>地址</td>
 </tr>
  //設置循環 $data是你傳過來的值  $index 下標  $item 是鍵
{loop $data $index_to $item_to}
 <tr height=18 style='height:13.5pt'>
  <td height=18 class=xl6332218 style='height:13.5pt;border-top:none'>{$item_to['order_bianhao']}</td>
  <td class=xl6332218 style='border-top:none;border-left:none'>{$item_to['egsname']} </td>
  <td class=xl6332218 style='border-top:none;border-left:none'>{$item_to['username']}</td>
  <td class=xl6332218 style='border-top:none;border-left:none'>{$item_to['phone']}</td>
  <td class=xl6332218 style='border-top:none;border-left:none'>{$item_to['Machine_type']}</td>
  <td class=xl6332218 style='border-top:none;border-left:none'>{$item_to['select_to']}</td>
//不這麼寫無法轉換時間格式
  {php $date = date('Y年m月d日 H時i分',$item_to['create_time']);}
  <td class=xl6332218 style='border-top:none;border-left:none'>{$date}</td>
  <td class=xl6332218 style='border-top:none;border-left:none'>{$item_to['money']}</td>
   <td class=xl6332218 style='border-top:none;border-left:none'>{$item_to['address']}</td>
 </tr>
 {/loop}

	

</table>

</div>


<!----------------------------->
<!--“從 EXCEL 發佈網頁”嚮導結束-->
<!----------------------------->
</body>

</html>

 
設置好後,只要引入頁面就會自動執行下載,保存位置需要在各自瀏覽器設置下載位置

 
希望能對大家有幫助!

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章