470,566 Members | 1,494 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,566 developers. It's quick & easy.

PHP & COM with MS Office

yayh
3
Dear all

i tried this fine artical which guide you to write php code to create ms office file using COM.


http://web.informbank.com/articles/t...-documents.htm

the problem that all the examples in this guide worked fine except the ms word example i am getting the following error:

this is the output:
I'm using MS Word 11.0
Fatal error: Call to a member function TypeText() on a non-object in C:\Inetpub\temp\index.php on line ...

$word->Selection->TypeText("Hello, universe!"); // error is here !

please help i tried everything...

note: i am using windows server 2003 sbs and php 5 and office 2003


**************************************

ok i have another code which also give error and did know how to solve it

this the error :

Loaded Word, version 11.0
Fatal error: Uncaught exception 'com_exception' with message 'Source: Microsoft Word
Description: Command failed' in C:\Inetpub\temp\index.php:... Stack trace: #0 C:\Inetpub\temp\index.php(...): variant->Open('C:/inetpub/temp...') #1 {main} thrown in C:\Inetpub\temp\index.php on line ...

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  //1. Instanciate Word
  3. $word = new COM("word.application") or die("Unable to instantiate Word");
  4. print "Loaded Word, version {$word->Version}\n";
  5. //2. specify the MS Word template document (with Bookmark TODAYDATE inside)
  6. $template_file = "C:/Inetpub/temp/reminder.doc";
  7. //3. open the template document
  8. $word->Documents->Open($template_file);
  9. //4. get the current date MM/DD/YYYY
  10. $current_date = date("m/d/Y");
  11. //5. get the bookmark and create a new MS Word Range (to enable text substitution)
  12. $bookmarkname = "TODAYDATE";
  13. $objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
  14. $range = $objBookmark->Range;
  15. //6. now substitute the bookmark with actual value
  16. $range->Text = $current_date;
  17. //7. save the template as a new document (c:/reminder_new.doc)
  18. $new_file = "C:/Inetpub/temp/reminder_new.doc";
  19. $word->Documents[1]->SaveAs($new_file);
  20. //8. free the object
  21. $word->Quit();
  22. $word->Release();
  23. $word = null;
  24.  
  25. ?>
Mar 15 '07 #1
2 2178
yayh
3
helloo help.......!!!
Mar 18 '07 #2
yayh
3
again helloo help ...!!!
Mar 26 '07 #3

Post your reply

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

Similar topics

reply views Thread by Michael Ransburg | last post: by
1 post views Thread by Prasad Patil | last post: by
3 posts views Thread by solomon_13000 | last post: by
1 post views Thread by keith | last post: by
3 posts views Thread by D. Kennedy | last post: by
2 posts views Thread by Amos Soma | last post: by
reply views Thread by salad | last post: by
reply views Thread by dt | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.