Msword Com issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ken Traub
    New Member
    • Feb 2012
    • 3

    Msword Com issue

    When I run a test code for com object in php I am getting a fatal error of PHP Fatal error: Call to a member function TypeText() on a non-object in C:\inetpub\wwwr oot\test.php on line 13. Here is the code I am using
    Code:
    <?php 
    // starting word 
    $word = new COM("word.application") or die("Unable to instanciate Word"); 
    echo "Loaded Word, version {$word->Version}\n"; 
    
    //bring it to front 
    $word->Visible = 1; 
    
    //open an empty document 
    $word->Documents->Add(); 
    
    //do some weird stuff 
    $word->Selection->TypeText("This is a test..."); 
    $word->Documents[1]->SaveAs("Useless test.doc"); 
    
    //closing word 
    $word->Quit(); 
    
    //free the object 
    $word->Release(); 
    $word = null; 
    
    header('Content-Type: application/msword'); 
    ?>
    Can someone please help me on this
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    it seems that $word->Selection is not an object. judging from the name, I’m not sure how PHP should select something …

    Comment

    • Ken Traub
      New Member
      • Feb 2012
      • 3

      #3
      Originally posted by Dormilich
      it seems that $word->Selection is not an object. judging from the name, I’m not sure how PHP should select something …
      If I remove the selection and make it
      Code:
      $word->TypeText("This is a test...");
      I get PHP Fatal error: Call to undefined method com::TypeText() in C:\inetpub\wwwr oot\test.php on line 13

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        according to tutorials your code should work, so the question is why it fails at that specific point.

        first thing to do is enable error reporting and error display, so you know of any warnings PHP issues.
        second, double-check all variables and the return values of functions to see if tere is a problem somewhere.

        Comment

        • ReedGrabne90
          New Member
          • Feb 2012
          • 1

          #5
          One word ' AWESOME

          Look forward to finding out more.

          Comment

          • Ken Traub
            New Member
            • Feb 2012
            • 3

            #6
            It seems the issue overall is for some reason it does not understand typetext(). Is there a php extension I should have added that this is in?

            Comment

            Working...