I've been playing with COM and PHP for quite a while now.  I have some
fairly basic scripts working, but can't seem to take advantage of MS Word
for more than the most basic open/write/save operations.  I've been using
the VB help and record macro capabilities of word to attempt to get some
things working in PHP.

I'm using W98, apache 1.3.12, and PHP as a DSO.  Word is Word 2000 (9.0).

Here is a simple example of a script that tries to generate some text, and then
do a search and replace to edit a field.

<?php 
$word=new COM("Word.Application.9") or die("Cannot start MS Word"); 
    print "Loaded word version ($word->Version)\n"; 
    $word->visible = 1 ; 
    $word->Documents->Add();
         
      $word->Selection->Typetext("This is a test"); 
          $word->Selection->Typetext("123"); 
          $word->Selection->Find->ClearFormatting;
          $word->Selection->Find->Text = "test";       ##<-##
          $word->Selection->Find->Forward = False;
          $word->Selection->Find->Wrap = wdFindContinue;
          $word->Selection->Collapse->Direction=wdCollapseEnd;
          $word->Selection->Find->Replacement->Text="rest";
          $word->Selection->Find->Execute;
    ?> 

I've created this by first recording a macro, and then trying to convert.
After commenting out various lines, it seems to hang on ##<-##
It prints out the first two typetext lines, and then a third "test" at the
end of the document, in highlighted form (it does not just highlight the
first instance of "test".

3 Questions:

  1) Is this revision of OS/MSword/Apache/PHP stable?
  2) Does the above syntax look correct, or have I missed something?
  3) Is it possible to pass variables to Word macros via PHP and
     drive the entire application from the other side?


Note that I haven't seemed to have any problems with Excel.


Thanks

--Bob



-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to