PHP 将html页面导出至Word


<?php
header("Content-Type: application/msword");
header("Content-Disposition: attachment; filename=doc.doc"); //指定文件名称
header("Pragma: no-cache");
header("Expires: 0");
$html = '<table border="1" cellspacing="2" cellpadding="2" width="90%" align="center">';
$html .= '<tr bgcolor="#cccccc"><td align="center">博客</td></tr>';
$html .= '<tr bgcolor="#f6f7fa"><td><span style="color:#FF0000;"><strong>PHP将网页代码导出word文档</strong></span></td></tr>';
$html .= '<tr><td align="center"><img src="/upload/header.gif"></td></tr>'; //自定义图片文件
$html .= '</table>';
echo $html;
?>

 

注:如果使用 smarty 方式 ,可在php页的最前面加入

header("Content-Type: application/msword"); 
header("Content-Disposition: attachment; filename=doc.doc"); //指定文件名称 
header("Pragma: no-cache");
header("Expires: 0");

即可。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM