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