【发布时间】:2012-04-20 14:12:08
【问题描述】:
我正在尝试将 word 文档转换为文本,并使用以下代码:
public function executeManoj() {
$filename='C:\xampp\htdocs\branch.com\web\greenwich-beer-and-jazz-application-form.doc';
$TXTfilename = $filename . ".txt";
$word = new COM("word.application") or die("Unable to instantiate Word object");
$word->Documents->Open($filename);
// the '2' parameter specifies saving in txt format
$word->Documents[1]->SaveAs($TXTfilename ,2);
$word->Documents[1]->Close(false);
$word->Quit();
$word->Release();
$word = NULL;
unset($word);
$content = file_get_contents($TXTfilename);
//unlink($TXTfilename);
exit;
}
但它会导致错误提示
“创建 COM 对象 `word.application' 失败:语法无效”....
我在 xammp 中设置了“允许服务与桌面交互”。
我需要在它之前安装任何软件吗?
【问题讨论】:
-
假设您已安装 Office - 如果您在执行
$word = new COM之前加载类型库会发生什么情况。所以在com_load_typelib('Word.Application');上方添加这行代码