【发布时间】:2026-01-17 03:45:01
【问题描述】:
Windows 7 Professional x64 - WAMP 服务器 2.4
Apache 版本 (x32):2.4.4
PHP 版本 (x32):5.4.16
Office 2003 - 与旧服务器版本相同
我有一个旧程序,它可以读取共享驱动器上的本地 .doc 文件,将内容插入书签,然后在将这些文件转换为 .pdf 并通过电子邮件发送给我们的客户之前保存这些文件。在其他人告诉我之前,I am VERY AWARE that this is not a recommended or supported way to do things. 只需要让这个遗留代码在新硬件上运行,这样我就可以完成一个更新的软件的工作,该软件最终将取代它并避免一起使用 COM 脚本。
最近运行此软件的服务器变得慢得令人难以忍受。我们正在设置一个新服务器以将其移至该服务器,但我在新环境中遇到了软件出现停止显示的严重错误:
以下代码有效且没有问题:
// starting word
$word = new COM("Word.Application") or die("Unable to instantiate Word");
echo "Loaded Word, version {$word->Version}\n";
$word->Visible = 0;
//open an empty document
$word->Documents->Add();
$word->Selection->TypeText("This is a test...");
$word->ActiveDocument->saveAs('C:\test.doc');
echo "File saved\n";
//closing word
$word->Quit();
//free the object
$word = null;
echo "Word closed\n";
以下代码永远挂起,永远不会超过 $word->Documents->Open();行。
// 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 = 0;
$word->Documents->Open('C:\test.doc') or die ('Could not open file');
//closing word
$word->Quit();
//free the object
$word = null;
echo "Word closed\n";
请帮忙!看到 PHP/COM 可以创建一个新文件并保存它让我觉得这是可能的,但是在幕后隐藏了一些权限问题,阻止 Word 打开现有文件。
【问题讨论】: