您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

php 网页生成word文档的实例程序

2024/4/19 10:25:52发布5次查看
php 网页生成word文档的实例程序 在需要的朋友可参考一下。
在这篇文章中主要解决两个问题:
1:在php中如何把html中的内容生成到word文档中
2:php把html中的内容生成到word文档中时,不居中显示问题,即会默认按照web视图进行显示。
3:php把html中的内容生成到word文档中时,相关样式不兼容问题
正文:
代码如下 复制代码
echo '
print
';echo '
';
    echo 数字化教学系统电子备课稿
学科 语文学校 实验中学
    ;
echo '
';                ob_start(); //打开缓冲区
 header(cache-control: public);
header(content-type: application/octet-stream);
header(accept-ranges: bytes);
if (strpos($_server[http_user_agent],'msie')) {
  header('content-disposition: attachment; filename=test.doc');
  }else if (strpos($_server[http_user_agent],'firefox')) {
  header('content-disposition: attachment; filename=test.doc');
  } else {
  header('content-disposition: attachment; filename=test.doc');
  }
  header(pragma:no-cache);
header(expires:0);
ob_end_flush();//输出全部内容到浏览器
注:以上代码部分提供了在php程序文件中生成内容到word文档中并提供下载功能。
例子
 代码如下 复制代码
试卷生成
include('head.php');
require ('dbconnect.php');
?>
difficulty.
;
$cout.=   .$row->content.
;
}//while?>
';
}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 class end-------*/
$word=new word;
$word->start();
echo $cout;
$wordname=word/.time()..doc;
$word->save($wordname);//保存word并且结束.
?>
试卷已经生成,请点击这里查看
您输入的条件不足,请重新输入!
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录