Search and Replace with WinWord and COM Objects?
| From: | jon | Date: | Mon, 01 Dec 2003 22:18:45 +0000 |
| Subject: | Search and Replace with WinWord and COM Objects? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-171510@lists.php.net to get a copy of this message | ||
Hey folks...
Hopefully, I'm not the only person out there trying this stuff... but I
haven't been able to find much documentation. I'm trying to do basic
search and replace with Word XP, but am not having any success...
The basics work -- I can connect via com, write some stuff, save a file,
etc... but when it comes to the actual search and replace, it gets ugly.
Here's my sample code:
<?php
$word = new COM("word.application") or die("Unable to instantiate
Word");
print "Loaded word version ($word->Version)\n";
$word->visible = true;
$word->Documents->Add();
$word->Selection->Typetext("This is a test");
$word->Selection->Typetext(" 123");
$word->Selection->Find->ClearFormatting();
$word->Selection->Find->Execute
("test","pain",True,'wdFindContinue',False,False,False,False,False,False
);
$word->Documents[1]->SaveAs("c:\wordTest\Useless test5.doc");
?>
Here's the output I get:
Loaded word version (10.0)
Warning: (null)(): Invoke() failed: Exception occurred. Source:
Unavailable Description: Unavailable in C:\Program Files\Apache
Group\Apache2\htdocs\wordFix.php on line 11
Any help would be greatly appreciated...
-- jon
-------------------
jon roig
web developer
email: jon@trafficdesigns.com
phone: 888.230.7557
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.544 / Virus Database: 338 - Release Date: 11/25/2003