Home > Backend Development > PHP Tutorial > php如何读取word文档?

php如何读取word文档?

PHPz
Release: 2020-09-04 15:04:34
Original
6329 people have browsed it

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!");
Copy after login

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

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

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

$word->Visible = 0;
Copy after login

4、打开一个文档

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

5、读取文档内容

$test= $word->ActiveDocument->content->Text;
Copy after login

6、输出文档内容

echo $test;
Copy after login

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

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template