如何使用php實(shí)現(xiàn)html轉(zhuǎn)換word?針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。

創(chuàng)新互聯(lián)建站網(wǎng)站建設(shè)公司,提供成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);可快速的進(jìn)行網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,是專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
php實(shí)現(xiàn)html轉(zhuǎn)換word的方法:1、通過(guò)mnt介質(zhì),生成word,代碼為【composer require cshaptx4869/html2word】;2、html文件直接寫(xiě)入word,且將圖片轉(zhuǎn)為base64格式。
php實(shí)現(xiàn)html轉(zhuǎn)換word的方法:
1、通過(guò)mnt這個(gè)介質(zhì),生成word
composer require cshaptx4869/html2word
<?php
/**
* @desc 方法一、生成word文檔
* @param $content
* @param string $fileName
*/
function createWord($content = '', $fileName = '')
{
if (empty($content)) {
return;
}
$content='<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 charset="UTF-8" />'.$content.'</html>';
if (empty($fileName)) {
$fileName = date('YmdHis').'.doc';
}
file_put_contents($fileName, $content);
}2、html文件直接寫(xiě)入word
注意:如果有圖片的話,轉(zhuǎn)為base64格式
<?php/**
* @desc 方法二、生成word文檔并下載
* @param $content
* @param string $fileName
*/
function downloadWord($content, $fileName=''){
if(empty($content)){
return;
}
if (empty($fileName)) {
$fileName = date('YmdHis').'.doc';
} // header("location:xxx.doc");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename={$fileName}");
$html = '<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
xmlns="http://www.w3.org/TR/REC-html40">';
$html .= '<head><meta http-equiv="Content-Type" content="text/html;charset="UTF-8" /></head>';
echo $html . '<body>'.$content .'</body></html>';
}
createWord(file_get_contents('html2word.html'));
downloadWord(file_get_contents('html2word.html'));關(guān)于如何使用php實(shí)現(xiàn)html轉(zhuǎn)換word問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
文章標(biāo)題:如何使用php實(shí)現(xiàn)html轉(zhuǎn)換word
網(wǎng)站URL:http://www.yijiale78.com/article46/pcseeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、App開(kāi)發(fā)、App設(shè)計(jì)、標(biāo)簽優(yōu)化、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)