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

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

Jun 13, 2016 am 10:20 AM
com gt quot wamp word

[提问]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-&gt;OPen("F:/wamp/www/oa/111.doc"); //读取文档内容 $test= $word-&gt;ActiveDocument-&gt;content-&gt;Text; echo $test; echo "<br>"; //将文档中需要换的变量更换一下$test=str_replace("","这是变量",$test);echo $test;$word-&gt;Documents-&gt;Add(); // 在新文档中添加文字 $word-&gt;Selection-&gt;TypeText("$test"); //把文档保存在目录中 $word-&gt;Documents[1]-&gt;SaveAs("F:\wamp\www\oa\111.doc"); // 关闭与COM组件之间的连接 $word-&gt;Quit(); ?&gt;
Copy after login

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 of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to cancel automatic word wrapping in word How to cancel automatic word wrapping in word Mar 19, 2024 pm 10:16 PM

How to cancel automatic word wrapping in word

Detailed explanation of how to display the ruler in Word and how to operate the ruler! Detailed explanation of how to display the ruler in Word and how to operate the ruler! Mar 20, 2024 am 10:46 AM

Detailed explanation of how to display the ruler in Word and how to operate the ruler!

How to add handwritten signature to word document How to add handwritten signature to word document Mar 20, 2024 pm 08:56 PM

How to add handwritten signature to word document

How to set page margins for Word How to set page margins for Word Mar 19, 2024 pm 10:00 PM

How to set page margins for Word

How to draw a dotted line in word How to draw a dotted line in word Mar 19, 2024 pm 10:25 PM

How to draw a dotted line in word

Specific steps to delete down arrow in Word! Specific steps to delete down arrow in Word! Mar 19, 2024 pm 08:50 PM

Specific steps to delete down arrow in Word!

Where is the shading setting in word? Where is the shading setting in word? Mar 20, 2024 am 08:16 AM

Where is the shading setting in word?

How to automatically sort word serial numbers How to automatically sort word serial numbers Mar 20, 2024 pm 09:20 PM

How to automatically sort word serial numbers

See all articles