700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 用php生成内容为html的word文档 微软的office打不开问题

用php生成内容为html的word文档 微软的office打不开问题

时间:2022-03-11 13:49:23

相关推荐

用php生成内容为html的word文档 微软的office打不开问题

function created_word(){$str_html = return_html();$path = 'folder/'.date('Y-m-d');$file_name = $path.'/'.date('H-i-s').'__'.time().'.doc';if(!file_exists($path)){// 判断路径是否存在,如果不存在则mkdir创建,并写入权限mkdir($path);chmod($path,0777);}$result = file_put_contents($file_name,$str_html);}function return_html(){$str_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="/office//12/omml"=xmlns="/TR/REC-html40"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>';$str_html.='<h2 style="text-align: center;">内容</h2>';$str_html.='</html>';return $str_html;}

一般不插入html标签和head标签直接插入html的代码会导致微软软件打不开,不会自动识别内容是html格式的。用WPS可以打开,加上这个html后就可以直接用微软打开了。

觉得有用或者解决你的问题了就点个赞留个言,虽然我也不经常来看,哈哈

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。