Dear all
i tried this fine artical which guide you to write php code to create ms office file using COM.
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("Hell o, 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 ...
i tried this fine artical which guide you to write php code to create ms office file using COM.
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("Hell o, 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 ...
Code:
<?php
//1. Instanciate Word
$word = new COM("word.application") or die("Unable to instantiate Word");
print "Loaded Word, version {$word->Version}\n";
//2. specify the MS Word template document (with Bookmark TODAYDATE inside)
$template_file = "C:/Inetpub/temp/reminder.doc";
//3. open the template document
$word->Documents->Open($template_file);
//4. get the current date MM/DD/YYYY
$current_date = date("m/d/Y");
//5. get the bookmark and create a new MS Word Range (to enable text substitution)
$bookmarkname = "TODAYDATE";
$objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
$range = $objBookmark->Range;
//6. now substitute the bookmark with actual value
$range->Text = $current_date;
//7. save the template as a new document (c:/reminder_new.doc)
$new_file = "C:/Inetpub/temp/reminder_new.doc";
$word->Documents[1]->SaveAs($new_file);
//8. free the object
$word->Quit();
$word->Release();
$word = null;
?>
Comment