使用Office Word通过PHP读取文档文件 [英] Using Office Word to read doc files with PHP
本文介绍了使用Office Word通过PHP读取文档文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将PHP与word.application
一起使用来读取文件.它根本不会打开文件.它呼应了正确的版本.
I am trying to use PHP with word.application
to read a file. It simply will not open the file. It's echoing the right version.
$w = new COM("word.application") or die("Is office installed?");
echo 'Loaded Word, version ' . $w->Version . '<br>';
$w->Visible = false;
$w->Documents->Open(realpath('test.docx'));
$content = (string) $w->ActiveDocument->Content;
echo $content;
$w->Quit();
$w->Release();
$w = null;
我得到了错误:
Uncaught exception 'com_exception' with message 'Source: Microsoft Word
Description: This command is not available because no document is open.'
感觉这是某种许可问题.除了使用realpath之外,我还尝试放置test.docx
的路径,但这没有帮助.还尝试将其放在我的C驱动器的根目录中.我正在使用Windows 7 Professional和Microsoft Office 2007.
It feels like it's some kind of permission problem. I tried to put the path of the test.docx
besides using realpath and that did not help. Also tried to put it in the root of my C drive. I am using Windows 7 Professional and Microsoft Office 2007.
推荐答案
- 尝试在上说一个file_exists 文件路径.
- 如果可行,请尝试 file_get_contents,看看是否可以 阅读.
- Try doing a file_exists on said file/path.
- If that works, try file_get_contents and see if you can read it.
如果一切正常-那么权限/等不是问题.
If that all works - then it's not a problem with permissions/etc.
这篇关于使用Office Word通过PHP读取文档文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文