Solved

Word and COM

Posted on 2004-08-18
3
368 Views
Last Modified: 2008-02-01
Reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrtskhowtoreplacetext.asp

Ok so I tried to mimick the code C# in PHP, came up with the following code:

<?php

$word = new COM("Word.Application") or die("Unable to create Word");

$word->Visible = TRUE;

$empty = new VARIANT();

$word->Application->ChangeFileOpenDirectory("C:\\");
$word->Documents->Open("test.doc");

$word->Selection->Find->ClearFormatting();
$word->Selection->Find->Text = "Php";

$word->Selection->Find->Replacement->ClearFormatting();
$word->Selection->Find->Replacement->Text = "Hi";

$word->Selection->Find->Execute(&$empty,
&$empty,&$empty,&$empty,
&$empty,&$empty,&$empty,
&$empty,&$empty,&$empty,
$word->WdReplace->wdReplaceAll,&$empty,&$empty,
&$empty,&$empty);



$word->Quit($empty,$empty,$empty);

?>

And it does not seem to work. It just times out, can somebody see what I might be missing?
0
Comment
Question by:drakkarnoir
  • 2
3 Comments
 

Author Comment

by:drakkarnoir
ID: 11833456
Fatal error: Uncaught exception 'com_exception' with message 'Unable to lookup `WdReplace': Unknown name. ' in C:\word.php:25 Stack trace: #0 {main} thrown in C:\word.php on line 25
0
 
LVL 7

Accepted Solution

by:
petoskey-001 earned 500 total points
ID: 11838106
I've seen this before.  Try the code from this previous answer and see if it works for you.
http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20306226.html
0
 

Author Comment

by:drakkarnoir
ID: 11848761
Going to do this with .NET, thanks guys.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question