PHP 的 Word 自动化问题

发布于 2024-08-06 10:16:02 字数 819 浏览 3 评论 0原文

我一直在尝试自动打开和填充网络上的 Word 文件,但在尝试从映射的网络驱动器打开文件时遇到了问题。我可以从 c:\ 驱动器打开该文件,并将 Apache 设置更改为以用户身份运行,而不是作为本地服务运行。该脚本在 Zend 环境中运行得很好,做了它应该做的一切,但在 Apache 上它读取目标目录,但无法使用 COM 打开文件。 (该目录是一个 Linux 网络存储设备,我有读/写访问权限。)

try {
 com_load_typelib('Word.Application');
 $word = new COM("Word.Application") or die ("Can't start Word");
 $word->visible = 1;

 $handle = opendir('\\\\<host ip addy>\\<sharename>\\<directory>');
 echo $handle . "\n";
 while (false !== ($file = readdir($handle))) {
    echo "$file\n";
 }
 $word->Documents->Open("\\\\<host ip addy>\\<sharename>\\<directory>\\test.doc");

 $word->Documents[1]->Close();
 $word->Quit();
 $word=null;
} catch (com_exception $ce) {
    echo $ce->getMessage;
 }

如果您有任何关于解决该问题的想法,我将不胜感激。

I've been trying to automate opening and populating a Word file on network but came across an issue when trying to open the file from a mapped network drive. I can open the file from my c:\ drive and I changed the Apache settings to run as a user rather than as a local service. The script runs perfectly well in the Zend environment doing everything it should but on Apache it reads the target directory but cannot open the file using COM. (The directory is a Linux network storage device and I do have read/write access.)

try {
 com_load_typelib('Word.Application');
 $word = new COM("Word.Application") or die ("Can't start Word");
 $word->visible = 1;

 $handle = opendir('\\\\<host ip addy>\\<sharename>\\<directory>');
 echo $handle . "\n";
 while (false !== ($file = readdir($handle))) {
    echo "$file\n";
 }
 $word->Documents->Open("\\\\<host ip addy>\\<sharename>\\<directory>\\test.doc");

 $word->Documents[1]->Close();
 $word->Quit();
 $word=null;
} catch (com_exception $ce) {
    echo $ce->getMessage;
 }

I'd be grateful for any thoughts on solving the issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红尘作伴 2024-08-13 10:16:02

拥有读/写访问权限,但是 Apache 会进行处理吗?

您是否收到可重现的错误消息?

You have read/write access, but does the Apache process?

Are you getting a reproducible error message?

尾戒 2024-08-13 10:16:02

我已将 Apache 设置为以我的帐户运行,该帐户昨天失败了(重新启动服务器后),但重新启动我的计算机似乎已将其解开并以正确的权限运行所有内容。

I had set Apache to run as my account which failed yesterday (after restarting the server) but restarting my machine seems to have unknotted it and got everything running with the right permissions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文