1.方法
public function word() {
$xlsModel = M('api_aliucheng');
$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();
$content='';
//$content = str_replace("src=\"/", "src=\"http://localhost:8087/", '<img src="waters/Public/uploads/anzhuang//20180518054237.jpg">');//给是相对路径的图片加上域名变成绝对路径,导出来的word就会显示图片了
foreach ($Data as $key => $val)
{ $content .= '<table border="0" align="center" width="600" height="800">
<tr>
<td>用户名字:</td>
<td>' . $val['u_name'] . '</td>
</tr>
<tr>
<td>家庭地址:</td>
<td>' . $val['u_addres'] . '</td>
</tr>
<tr>
<td>手机号:</td>
<td>' . $val['u_tel'] . '</td>
</tr>
<tr>
<td>身份证号:</td>
<td>' . $val['u_card'] . '</td>
</tr>
<tr>
<td>申报时间:</td>
<td>' . $val['u_time'] . '</td>
</tr>
<tr>
<td>用水性质:</td>
<td>' . $val['water_xingzhi'] . '</td>
</tr>
<tr>
<td>安装类别:</td>
<td>' . $val['u_class'] . '</td>
</tr>
<tr>
<td>身份证正面:</td>
<td><img height="240" width="300" src="http://60.205.111.111:8087/waters/Public'.$val['u_imgz'].'"></td>
</tr>
<tr>
<td>身份证反面:</td>
<td><img height="240" width="300" src="http://60.205.111.111:8087/waters/Public'.$val['u_imgf'].'"></td>
</tr>
<tr>
<td>水表口径;</td>
<td>' . $val['water_kj'] . '</td>
</tr>
<tr>
<td>水表位置:</td>
<td>' . $val['water_wz'] . '</td>
</tr>
<tr>
<td>区域位置;</td>
<td>' . $val['water_quyu'] . '</td>
</tr>
<tr>
<td>施工日期:</td>
<td>' . $val['water_start_time'] . '</td>
</tr>
<tr>
<td>施工人员:</td>
<td>' . $val['water_start_peo'] . '</td>
</tr>
<tr>
<td>施工经理:</td>
<td>' . $val['water_start_jingli'] . '</td>
</tr>
<tr>
<td>水表底数:</td>
<td>' . $val['watch_num'] . '</td>
</tr>
<tr>
<td>抄表日期:</td>
<td>' . $val['watch_time'] . '</td>
</tr>
<tr>
<td>抄表人员:</td>
<td>' . $val['watch_peo'] . '</td>
</tr>
<tr>
<td>收费经理:</td>
<td>' . $val['moneyjingli_name'] . '</td>
</tr> </table>
';
}
$filename = $_SESSION['account'].date('_YmdHis');
$filename = iconv('utf-8', 'gb2312', $filename);
header('pragma:public');
header('Content-type:application/vnd.ms-word;charset=utf-8;name="' . $filename . '".doc');
header("Content-Disposition:attachment;filename=$filename.doc");//attachment新窗口打印inline本窗口打印
$html = '<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 http-equiv="Content-Type" content="text/html; charset=UTF-8"/>';//这句不能少,否则不能识别图片
echo $html . $content . '</html>'; }
本方法是把html页面导出到word(web视图)
导出结果如下图。这样就解决了PHPword导出图片不显示的问题