1.方法
1 public function word() 2 3 { 4 $xlsModel = M('api_aliucheng'); 5 $Data = $xlsModel->Field('id,u_name,u_addres,u_tel,u_card,u_time,u_imgz,u_imgf,u_class,b_one_beizhu,b_shenhe_p,water_kj,water_wz,water_quyu,water_start_time,water_start_peo,water_start_jingli,water_beizhu,water_xingzhi,watch_num,watch_time,watch_peo,moneyjingli_name,moneyjingli_beizhu,jingli_name')->where(array('jingli_state_san' => 1))->select(); 6 $content=''; 7 //$content = str_replace("src=\"/", "src=\"http://localhost:8087/", '<img src="waters/Public/uploads/anzhuang//20180518054237.jpg">');//给是相对路径的图片加上域名变成绝对路径,导出来的word就会显示图片了 8 foreach ($Data as $key => $val) 9 { 10 11 $content .= '<table border="0" align="center" width="600" height="800"> 12 <tr> 13 <td>用户名字:</td> 14 <td>' . $val['u_name'] . '</td> 15 </tr> 16 <tr> 17 <td>家庭地址:</td> 18 <td>' . $val['u_addres'] . '</td> 19 </tr> 20 <tr> 21 <td>手机号:</td> 22 <td>' . $val['u_tel'] . '</td> 23 </tr> 24 <tr> 25 <td>身份证号:</td> 26 <td>' . $val['u_card'] . '</td> 27 </tr> 28 <tr> 29 <td>申报时间:</td> 30 <td>' . $val['u_time'] . '</td> 31 </tr> 32 <tr> 33 <td>用水性质:</td> 34 <td>' . $val['water_xingzhi'] . '</td> 35 </tr> 36 <tr> 37 <td>安装类别:</td> 38 <td>' . $val['u_class'] . '</td> 39 </tr> 40 <tr> 41 <td>身份证正面:</td> 42 <td><img height="240" width="300" src="http://60.205.111.111:8087/waters/Public'.$val['u_imgz'].'"></td> 43 </tr> 44 <tr> 45 <td>身份证反面:</td> 46 <td><img height="240" width="300" src="http://60.205.111.111:8087/waters/Public'.$val['u_imgf'].'"></td> 47 </tr> 48 <tr> 49 <td>水表口径;</td> 50 <td>' . $val['water_kj'] . '</td> 51 </tr> 52 <tr> 53 <td>水表位置:</td> 54 <td>' . $val['water_wz'] . '</td> 55 </tr> 56 <tr> 57 <td>区域位置;</td> 58 <td>' . $val['water_quyu'] . '</td> 59 </tr> 60 <tr> 61 <td>施工日期:</td> 62 <td>' . $val['water_start_time'] . '</td> 63 </tr> 64 <tr> 65 <td>施工人员:</td> 66 <td>' . $val['water_start_peo'] . '</td> 67 </tr> 68 <tr> 69 <td>施工经理:</td> 70 <td>' . $val['water_start_jingli'] . '</td> 71 </tr> 72 <tr> 73 <td>水表底数:</td> 74 <td>' . $val['watch_num'] . '</td> 75 </tr> 76 <tr> 77 <td>抄表日期:</td> 78 <td>' . $val['watch_time'] . '</td> 79 </tr> 80 <tr> 81 <td>抄表人员:</td> 82 <td>' . $val['watch_peo'] . '</td> 83 </tr> 84 <tr> 85 <td>收费经理:</td> 86 <td>' . $val['moneyjingli_name'] . '</td> 87 </tr> 88 89 </table> 90 '; 91 } 92 $filename = $_SESSION['account'].date('_YmdHis'); 93 $filename = iconv('utf-8', 'gb2312', $filename); 94 header('pragma:public'); 95 header('Content-type:application/vnd.ms-word;charset=utf-8;name="' . $filename . '".doc'); 96 header("Content-Disposition:attachment;filename=$filename.doc");//attachment新窗口打印inline本窗口打印 97 $html = '<html xmlns:o="urn:schemas-microsoft-com:office:office" 98 xmlns:w="urn:schemas-microsoft-com:office:word" 99 xmlns="http://www.w3.org/TR/REC-html40"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>';//这句不能少,否则不能识别图片 100 echo $html . $content . '</html>'; 101 102 }
本方法是把html页面导出到word(web视图)
导出结果如下图。这样就解决了PHPword导出图片不显示的问题
成为不了聪明的人,那就做一个有耐心、肯钻研,坚持不懈,永不放弃的人……