当前位置: 移动技术网 > IT编程>开发语言>PHP > 在PHP中读取和写入WORD文档的代码

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

2019年05月12日  | 移动技术网IT编程  | 我要评论

复制代码 代码如下:

<? 
// 建立一个指向新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(); 
?> 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网