php导出word文档 不需要下载phpword
复制一下代码执行方法可以直接导出word ,我是放在TP5里面执行的
public function download(){
$content = '<center><table border="0" cellspacing="0" cellpadding="0" width="80%">';
$content .= '<tr><td style="text-align: center;">商品名称</td><td style="text-align: center;">价格</td><td style="text-align: center;">描述</td><td style="text-align: center;">上下架</td></tr>';
$content .= '<tr><td style="text-align: center;">衣服</td><td style="text-align: center;">120元</td><td style="text-align: center;">描述</td><td style="text-align: center;">上架</td></tr>';
$content .= '<tr><td style="text-align: center;">包包</td><td style="text-align: center;">90元</td><td style="text-align: center;">描述</td><td style="text-align: center;">下架</td></tr>';
$content = $content.'</table></center>';
$filename = "测试"; //word文档名称
header('pragma:public');
header('Content-type:application/vnd.ms-word;charset=utf-8;name="'.$filename.'".doc');
header("Content-Disposition:attachment;filename=$filename.doc");
$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>';
}
运行结果