Home  >  Article  >  php教程  >  直接用php创建word文档代码(系统无需安装word软件)

直接用php创建word文档代码(系统无需安装word软件)

WBOY
WBOYOriginal
2016-06-13 11:24:13689browse

直接用php创建word文档代码(系统无需安装word软件)使用方法: 首先用$word->start()表示要生成word文件了。 然后你可以输出任何的HTML代码,不论是从文件读过来再写到这里, 还是直接在这里输出HTML,都没有关系。

直接用php教程创建word文档代码(系统无需安装word软件)
使用方法:
首先用$word->start()表示要生成word文件了。 然后你可以输出任何的html代码,不论是从文件读过来再写到这里, 还是直接在这里输出html,都没有关系。
等你输出完毕后,用$word->save($path)方法,其中$path是你想 生成的word文件的名称(可以给出完整的路径).当你使用了$word->save() 方法后,这后面的任何输出都和word文件没有关系了,也就是说word的生成 工作就完成了。之后就和你平常使用php的方式一样拉。随便你输出什么东西, 都直接在浏览器里输出,而不会写到word里面去。

*/

class word

function start()
{
ob_start();
print'

xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/tr/rec-html40">';

}

function save($path)
{

print "";
$data = ob_get_contents();

ob_end_clean();

$this->wirtefile ($path,$data);
}

function wirtefile ($fn,$data)
{

$fp=fopen($fn,"wb");
fwrite($fp,$data);
fclose($fp);
}

}
//生成word调用方法
include("word.php");
$word=new word;
$word->start();


Statement:
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