Heim >Backend-Entwicklung >PHP-Tutorial >php如何读取word文档?

php如何读取word文档?

PHPz
PHPzOriginal
2016-06-06 16:43:366322Durchsuche

php开发过程中可能会有word文档的读取问题,那么php如何读取word文档?可以利用com组件来完成此项操作。下面本篇文章给大家介绍一下。

php如何读取word文档?

php读取word文档的方法:

一、先开启php.ini的COM,操作如下 

1.extension=php_com_dotnet.dll 

2.com.allow_dcom = true 

二、开启之后就可以试下如下操作 

1、建立一个指向新COM组件的索引

$word = new COM("word.application") or die("Can’t start Word!");

2、显示目前正在使用的Word的版本号

echo "Loading Word, v. {$word->Version}";

3、把它的可见性设置为0(假),如果要使它在最前端打开,使用1(真)

$word->Visible = 0;

4、打开一个文档

$word->Documents->open(dirname(__FILE__)."/1.doc");

5、读取文档内容

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

6、输出文档内容

echo $test;

更多相关知识,请访问 PHP中文网!!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn