php完成html转换word的办法:一、经过mnt介质,天生word,代码为【composer require cshaptx4869/html2word】;二、html文件间接写入word,且将图片转为base64格局。
php完成html转换word的办法:
一、经过mnt这个介质,天生word
composer require cshaptx4869/html2word
<?php /** * @desc 办法1、天生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); }
二、html文件间接写入word
留意:假如有图片的话,转为base64格局
<?php/** * @desc 办法2、天生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/o妹妹l" 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'));
相干学习保举:PHP编程从入门到通晓
以上就是php若何完成html转换word?的具体内容,更多请存眷资源魔其它相干文章!
标签: php php教程 html php故障解决 php使用问题 word
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!