标签:
public function actionWord() { $userList = array( 0=>array(‘total_price‘=>166 ,‘area_name‘=>‘北辰‘,‘user_shop_name‘=>‘北京将台玉花餐厅‘,‘user_name‘=>‘测试‘,‘user_address‘=>‘大山子社区京客隆超市隔壁‘,‘user_tel‘=>‘15812341111‘, ‘orders‘=>array( 0=>array( ‘contents‘=>array( 0=>array(‘name‘=>‘五得利特精面粉1‘,‘unit_price‘=>‘88‘,‘amount‘=>‘2‘,‘unit‘=>‘袋‘), ), ‘dec_price‘=>10, ‘total_price‘=>166 )) ), 1=>array(‘total_price‘=>166 ,‘area_name‘=>‘北辰‘,‘user_shop_name‘=>‘北京将台玉花餐厅‘,‘user_name‘=>‘测试‘,‘user_address‘=>‘大山子社区京客隆超市隔壁金卡解放路加长‘,‘user_tel‘=>‘15812341111‘, ‘orders‘=>array( 0=>array( ‘contents‘=>array( 0=>array(‘name‘=>‘五得利特精面粉4‘,‘unit_price‘=>‘88‘,‘amount‘=>‘2‘,‘unit‘=>‘袋‘), 1=>array(‘name‘=>‘五得利特精面粉5‘,‘unit_price‘=>‘88‘,‘amount‘=>‘2‘,‘unit‘=>‘袋‘), 2=>array(‘name‘=>‘五得利特精面粉6‘,‘unit_price‘=>‘88‘,‘amount‘=>‘2‘,‘unit‘=>‘袋‘)), ‘dec_price‘=>10, ‘total_price‘=>166 )) ), ); $html = ‘<meta charset="utf-8">‘; foreach($userList as $key=>$user){ $html_temp = ‘ <div style="OVERFLOW-Y: scroll; WIDTH: 100%; POSITION: HEIGHT: 200px" id="splist"> <table width="97%" align="center" style="WORD-BREAK: break-all" class="tableframe2"> <tbody> <tr><td align="center" colspan="3"><b><font size="5">蔬东坡(sdongpo.com)购物清单</font></b></td></tr> <tr><td align="center" colspan="3"><font size="2">——省钱才是硬道理</font></td></tr> <tr> <td width="48%" height="21" align="left"><b><font size="2">店名:‘.$user[‘user_shop_name‘].‘</font></b></td> <td width="18%" height="21" align="center"><b><font size="2">客户姓名:‘.$user[‘user_name‘].‘</font></b></td> <td width="30%" height="21" align="center"><b><font size="2">手机号码:‘.$user[‘user_tel‘].‘</font></b></td> </tr> <tr> <td width="48%" height="21" align="left"><b><font size="2">地址:‘.$user[‘user_address‘].‘</font></b></td> <td width="18%" height="21" align="center"><b><font size="2">所属地区:‘.$user[‘area_name‘].‘</font></b></td> <td width="30%" height="21" align="center"><b><font size="2">订购时间:2015-03-12</font></b></td> </tr> <tr> <td width="48%" height="21" align="left"><b><font size="2">商品名称</font></b></td> <td width="18%" height="21" align="center"><b><font size="2">规格</font></b></td> <td width="30%" height="21" align="center"><b><font size="2">数量</font></b></td> </tr> ‘; foreach($user[‘orders‘] as $order){ foreach($order["contents"] as $content){ $html_temp .=‘ <tr style="BACKGROUND-COLOR: #dae2ed"> <td width="48%" height="1" align="left"><font size="2">‘.$content[‘name‘].‘</font></td> <td width="18%" height="1" align="center"><font size="2">‘.$content[‘unit_price‘].‘元/‘.$content[‘unit‘].‘</font></td> <td width="30%" height="1" align="center"><font size="2">‘.$content[‘name‘].‘</font></td> </tr> ‘; } $html_temp .=‘ <tr><td align="left" colspan="3"><font size="2">优惠券:¥‘.$order[‘dec_price‘].‘</font></td></tr> ‘; } $html_temp .=‘ <tr><td align="left" colspan="3"><b><font size="3">总金额:¥‘.$user[‘total_price‘].‘</font></b></td></tr> </tbody> </table> </div> <hr> <br> ‘; $html .= $html_temp; } $this->start(); $wordname = ‘./phpword/‘.date("Y年m月d日").‘蔬东坡发货单‘.date("YmdHis"). rand(1, 99).".doc"; $wordname = iconv("utf-8", "GBK", $wordname); echo $html; $this->save($wordname); ob_flush();//每次执行前刷新缓存 flush(); echo json_encode($wordname); exit(‘xxx‘); } function start() { ob_start(); echo ‘<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <meta charset="UTF-8"> <head></head><body>‘; } function save($path) { echo "</body></html>"; $data = ob_get_contents(); ob_end_clean(); $this->wirtefile ($path,$data); } function wirtefile ($fn,$data) { $fp=fopen($fn,"wb"); fwrite($fp,$data); fclose($fp); }
标签:
原文地址:http://www.cnblogs.com/jami918/p/4378640.html