在PHP中读取和写入WORD文档的代码

yipeiwu_com6年前PHP代码库

复制代码 代码如下:

<? 
// 建立一个指向新COM组件的索引 
$word = new COM(”word.application”) or die(”Can't start Word!”); 
// 显示目前正在使用的Word的版本号 
//echo “Loading Word, v. {$word->Version}<br>”; 
// 把它的可见性设置为0(假),如果要使它在最前端打开,使用1(真) 
// to open the application in the forefront, use 1 (true) 
//$word->Visible = 0; 

//打?一个文档 
$word->Documents->OPen(”d:\myweb\muban.doc”); 
//读取文档内容 

$test= $word->ActiveDocument->content->Text; 

echo $test; 
echo “<br>”; 
//将文档中需要换的变量更换一下 
$test=str_replace(”<{变量}>”,”这是变量”,$test); 
echo $test; 
$word->Documents->Add(); 
// 在新文档中添加文字 
$word->Selection->TypeText(”$test”); 
//把文档保存在目录中 
$word->Documents[1]->SaveAs(”d:/myweb/comtest.doc”); 
// 关闭与COM组件之间的连接 
$word->Quit(); 
?> 

相关文章

php 安全过滤函数代码

复制代码 代码如下: //安全过滤输入[jb] function check_str($string, $isurl = false) { $string = preg_repl...

php中使用preg_replace函数匹配图片并加上链接的方法

介绍:preg_replace 执行正则表达式的搜索和替换,如果只是单纯的匹配字符串建议使用str_replace(),因为其执行效率高的多。mixed preg_replace ( m...

phpMyAdmin通过密码漏洞留后门文件

phpMyAdmin通过密码漏洞留后门文件

默认 phpMyAdmin:用户名 root 密码 root 或空登陆。 版本 2.11.3~2.11.4:用户名 'localhost'@'@" 登陆,无需密码。 版本...

php使用for语句输出三角形的方法

本文实例讲述了php使用for语句输出三角形的方法。分享给大家供大家参考。具体实现方法如下: <?php //phpinfo(); function Dis($n...

php依赖注入知识点详解

引言 你知道什么是依赖注入吗?依赖注入(DI)的概念虽然听起来很深奥,但是如果你用过一些新兴的php框架的话,对于DI一定不陌生,因 为它们多多少少都用到了依赖注入来处理类与类之间的依赖...