1.首先要把word、excel表放到文件的根目录下

2.定义了一个word类

<?php
class word
{ function start()
{
ob_start(); ob_start — 打开输出控制缓冲
} function save($path)
{
$data = ob_get_contents(); ob_get_contents — 返回输出缓冲区的内容
ob_end_clean(); ob_end_clean — 清空(擦除)缓冲区并关闭输出缓冲
$this->wirtetoword($path,$data);
}
function wirtetoword ($fn,$data)
{
$fp=fopen($fn,"w"); fopen — 打开文件或者 URL,第二个参数是表示以什么方式打开
fwrite($fp,$data); fwrite — 写入文件(可安全用于二进制文件)
fclose($fp); fclose — 关闭一个已打开的文件指针
}
}
?>

2.引用该类,并从数据库中调用nation表的数据

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<?php
if(!isset($_GET["id"]))
{
?>
<input type="button" name="submit" value="将表格内容保存到Word" onclick="window.location.href='main.php?id=print'">
<?php
}
?>
<?php
if($_GET["id"]!="")
{
include("word.class.php"); 将word类引用进来
$word=new word(); 对该类进行实例化
$word->start(); 调用start()方法,定义要保存表格的开始 } ?> <table border="1" cellspacing="0" cellpadding="0">
<tr><th>代号</th><th>名称</th></tr>
<?php
include("../gongju/DBDA.class.php");
$db=new DBDA();
$sql="select * from nation";
$attr=$db->Query($sql);
foreach($attr as $v)
{
echo "<tr><td>{$v[0]}</td><td>{$v[1]}</td></tr>";
} ?>
</table>
<?php
if($_GET["id"]!=""){
$word->save("data.doc"); 保存表格结束
} ?> </body>
</html>

最新文章

  1. Yii2.X 多语言-类图
  2. ansible-copy
  3. 9.9,新iPhone要来了,是欢呼,还是墙角画圈,一会儿见分晓
  4. 基础学习day10--异常、包
  5. iOS开发多线程篇—单例模式(ARC)
  6. android startActivityForResult(Intent intent, int requestCode) 整理与总结! .
  7. html-----018----HTML Web Server/HTML URL 字符编码
  8. Global build settings
  9. hibernate初体验
  10. linux下FFmpeg编译生成ffplay
  11. 新概念英语(1-45)The boss&#39;s letter
  12. Python__flask初识
  13. BZOJ_5118_Fib数列2_矩阵乘法+欧拉定理
  14. ReactNative之从“拉皮条”来看RN中的Spring动画
  15. Django Linux环境下部署CentOS7+Python3+Django+uWSGI+Nginx(含Nginx返回400问题处理、防火墙管理)
  16. MySQL ERROR 1130 (HY000): Host &#39;192.168.1.8&#39; is not allowed to connect to this MySQL server
  17. 用selenium获取cookies
  18. mac maven lombok报错
  19. apache atlas资料收集
  20. hping安装过程

热门文章

  1. hdu 5020(斜率的表示+STL)
  2. 四、Ubuntu 一些常用命令
  3. 批量Kill多个进程
  4. BZOJ3631 松鼠的新家(树链剖分)
  5. Python学习笔记——安装
  6. LeakCanary: 让内存泄露无所遁形
  7. 给java类加static修饰编译器会说什么?
  8. Nginx学习——Nginx进程间的通信
  9. 《转》 在C++中使用TinyXML2解析xml
  10. java查看工具jmap-windows