http://hi.baidu.com/qiaoyuetian/blog/item/f1265f50ac94756585352419.html
<?php
/*--------------------------------------------------------------
@功能描述:生成word文档
@创建时间:2007-4-2 18:10
@作者:流浪者 Mail:xsl2750565@126.com
--------------------------------------------------------------*/
class CreateWord
{
var $path = ""; //保存的路径
var $data = ""; //存入的数据
var $type = ""; //告诉程序是生成word还是excel
function CreateWord($path,$data,$type = "word") //构造函数初始化变量
{
$this ->path = $path;
$this ->data = $data;
$this ->type = $type;
$this ->Start();
$this ->Save();
}
function Start() //生成开始定义头
{
ob_start();
print"<html xmlns:o=/"urn:schemas-microsoft-com:office:office/"
xmlns:w=/"urn:schemas-microsoft-com:office:".$this ->type."/"
xmlns=/"http://www.w3.org/TR/REC-html40/">";
}
function Save() //保存数据
{
print "</html>";
ob_end_clean();
$this->WirteFile ();
}
function WirteFile () //写入数据
{
$fp=fopen($this ->path,"wb");
fwrite($fp,$this ->data);
fclose($fp);
}
}
?>
以下是调用 示例
<?
include("C_CreateWord.php");
$data = "id/tname/tcontent/tdatetime/n1/t圣诞节法/t大师傅/t2007-7-14";//可从数据库中取出最好格式化输出 方便以后重新导入数据库.
$word = new CreateWord("test.doc",$data,"word");
?>