在PHP中读取和写入WORD文档的代码
时间:2023-09-28 02:30:22
<?
// 建立一个指向新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,读取,写入,WORD
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
CentOS下使用yum安装python-pip失败的完美解决方法
2023-07-09 12:23:01
Python selenium模拟手动操作实现无人值守刷积分功能
2021-07-30 23:54:08
![](https://img.aspxhome.com/file/2023/6/97216_0s.jpg)
Sql Server中的事务介绍
2024-01-22 01:04:37
mysql 不等于 符号写法
2024-01-22 07:03:06
Go语言通过Luhn算法验证信用卡卡号是否有效的方法
2023-07-23 17:28:07
用pytorch的nn.Module构造简单全链接层实例
2022-01-04 00:00:17
MySQL索引用法实例分析
2024-01-22 16:42:22
Navicat数据存放位置和备份数据库路径设置方式
2024-01-16 14:32:53
![](https://img.aspxhome.com/file/2023/7/69257_0s.png)
用Python实现最速下降法求极值的方法
2023-05-04 20:03:34
![](https://img.aspxhome.com/file/2023/7/112977_0s.jpg)
vue多页面项目实现版本快照功能示例详解
2024-04-28 09:23:25
![](https://img.aspxhome.com/file/2023/0/133060_0s.png)
Python中List.count()方法的使用教程
2023-08-12 11:56:15
15个设计得最糟糕最变态的CAPTCHA验证码
2008-09-01 17:17:00
![](https://img.aspxhome.com/file/UploadPic/20089/1/200891172337638s.jpg)
Django路由层如何获取正确的url
2022-02-13 17:30:08
MySQL Replication中的并行复制示例详解
2024-01-29 02:49:03
简易CSS相册源代码
2008-04-18 12:28:00
matlab画三维图像的示例代码(附demo)
2023-10-03 11:39:44
![](https://img.aspxhome.com/file/2023/9/131869_0s.jpg)
SQL Server中导入导出数据的三种方式
2008-11-28 15:53:00
在pandas中一次性删除dataframe的多个列方法
2022-08-16 02:50:02
pytest使用parametrize将参数化变量传递到fixture
2022-03-28 23:30:18
无级分类的多级联动
2020-07-02 12:53:12