By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

Msword Com issue

P: 3
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\wwwroot\test.php on line 13. Here is the code I am using
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. // starting word 
  3. $word = new COM("word.application") or die("Unable to instanciate Word"); 
  4. echo "Loaded Word, version {$word->Version}\n"; 
  6. //bring it to front 
  7. $word->Visible = 1; 
  9. //open an empty document 
  10. $word->Documents->Add(); 
  12. //do some weird stuff 
  13. $word->Selection->TypeText("This is a test..."); 
  14. $word->Documents[1]->SaveAs("Useless test.doc"); 
  16. //closing word 
  17. $word->Quit(); 
  19. //free the object 
  20. $word->Release(); 
  21. $word = null; 
  23. header('Content-Type: application/msword'); 
  24. ?>
Can someone please help me on this
Feb 20 '12 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 5K+
P: 8,639
it seems that $word->Selection is not an object. judging from the name, Iím not sure how PHP should select something Ö
Feb 20 '12 #2

P: 3
If I remove the selection and make it
Expand|Select|Wrap|Line Numbers
  1. $word->TypeText("This is a test..."); 
I get PHP Fatal error: Call to undefined method com::TypeText() in C:\inetpub\wwwroot\test.php on line 13
Feb 20 '12 #3

Expert Mod 5K+
P: 8,639
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.
Feb 21 '12 #4

P: 1
Look forward to finding out more.
Feb 21 '12 #5

P: 3
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?
Feb 21 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.