php 读取 word

时间:2023-12-17 14:51:32

---恢复内容开始---

首先安装com扩展:

php.ini

php.ini 确保有此语句

[PHP_COM_DOTNET]
extension=php_com_dotnet.dll

php.ini中设置

com.allow_dcom = true

代码:

<?php
// starting word
$word = new COM("word.application") or die("Unable to instantiate Word");
echo "Loaded Word, version {$word->Version}\n"; //bring it to front
$word->Visible = 1; //open an empty document
$word->Documents->Add(); //do some weird stuff
$word->Selection->TypeText("This is a test...");
$word->Documents[1]->SaveAs("Useless test.doc"); //closing word
$word->Quit(); //free the object
$word = null;
?>

总是报这个错:

Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `wps.application' in F:\xampp\htdocs\php\curl\phpWord.php on line 2

找了好多解决方法,还是不行:

http://www.haosblog.com/?mod=article_read&id=386

算了,不用Com调用了,在网上搜了一个比较出名的库PHPWord,不需要安装,直接调用库文件就可以了。

地址:http://phpword.codeplex.com/documentation

更多:http://www.cnblogs.com/phphuaibei/archive/2011/11/30/2269427.html

下载的文件夹里面有许多丰富的例子,可以作为参考.

找了半天想读取word,可以没有找到文档,最后发现该库仅仅是创建word文件,不能读取

---恢复内容结束---