Home  >  Article  >  Backend Development  >  [提问]PHP 读取 word COM 组件的异常信息 小弟我很是无语啊

[提问]PHP 读取 word COM 组件的异常信息 小弟我很是无语啊

WBOY
WBOYOriginal
2016-06-13 13:33:301141browse

[提问]PHP 读取 word COM 组件的错误信息 我很是无语啊!!!!

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php // 建立一个指向新COM组件的索引 
$word = new COM("word.application") or die("Can't start Word!"); 
//打开一个文档 
$word->Documents->OPen("F:/wamp/www/oa/111.doc"); 
//读取文档内容 
$test= $word->ActiveDocument->content->Text; 
echo $test; 
echo "<br>"; 
//将文档中需要换的变量更换一下
$test=str_replace("","这是变量",$test);
echo $test;
$word->Documents->Add(); 
// 在新文档中添加文字 
$word->Selection->TypeText("$test"); 
//把文档保存在目录中 
$word->Documents[1]->SaveAs("F:\wamp\www\oa\111.doc"); 
// 关闭与COM组件之间的连接 
$word->Quit(); 

?>


IE 浏览器下的错误报告
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `word.application': 尚未调用 CoInitialize。 ' in F:\wamp\www\oa\newfile.php:3 Stack trace: #0 F:\wamp\www\oa\newfile.php(3): com->com('word.applicatio...') #1 {main} thrown in F:\wamp\www\oa\newfile.php on line 3

遨游下的错误报告
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `word.application': 尚未调用 CoInitialize。 ' in F:\wamp\www\oa\newfile.php:3 Stack trace: #0 F:\wamp\www\oa\newfile.php(3): com->com('word.applicatio...') #1 {main} thrown in F:\wamp\www\oa\newfile.php on line 3

我求解释



------解决方案--------------------
应该是第一个实例没有关闭

------解决方案--------------------
问题出你的第三行啊。还是致命错误。 "F:/wamp/www/oa/111.doc 与 F:\wamp\www\oa\111.doc 你这个路径不是有问题吗? 仔细检查。
Statement:
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