php生成简易word文档的方法

WBOY
Release: 2016-06-20 13:04:10
Original
1110 people have browsed it

在做php网站项目的时候,经常要在线导入数据文档。利用php生成word文档,生成的word文件可以用word,openoffice,wps等软件打开。

具体代码如下:

<p>function word($data,$fileName=''){</p>	if(empty($data)) return '';<br />	$data='<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">'.$data.'</html>';<br />	if(empty($fileName)) $fileName=date('YmdHis').'.doc';<br />	$fp=fopen($fileName,'wb');<br />	fwrite($fp,$data);<br />	fclose($fp);<br /><p>}</p>
Copy after login

示例如下:

<p><?php</p>$str='<title>利用php创建word文档</title><br /> <h1>利用php创建word文档</h1><br /> 作者:scutephp.com<br /><hr size=1><br /> <p>如果你打开word.doc,看到了这里的介绍,则说明word文档创建成功了。</p><br /><p><br /><b>版权所有:</b><br /><br>www.scutephp.com<br /><hr size=1>';<br />word($str);
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!