proctk Posted September 7, 2006 Share Posted September 7, 2006 HiI'm trying to get information for a mysql table and populate it into msword. below is some test code taht I'm working with but having no luck when I run it I get I believe it has to do with my file loaction but, Its saved in a folder on on the service. I tried setting the file address as c: etcbut get the same errorerrorFatal error: Uncaught exception 'com_exception' with message 'Unable to lookup `Document': Unknown name. ' in C:\MyServer\xampp\htdocs\familyclick\WordTest.php:8 Stack trace: #0 C:\MyServer\xampp\htdocs\familyclick\WordTest.php(8): unknown() #1 {main} thrown in C:\MyServer\xampp\htdocs\familyclick\WordTest.php on line 8<?PHP[code=php:0]$word=new COM("word.application") or die ("cannot start MS Word");$userfile = "familyclick\formtemplates\letter.doc";$word->visible=1;$word->Document->open($userfile);$word->Application->Run("bkfirstname");$word->selection->TypeText($data1);$word->Application->Run("bklastname");$word->selection->TypeText($data2);$word->Application->Run("bkcity");$word->selection->TypeText($data3);$word->Application->Run("street_address");$word->selection->TypeText($data4);$word->Application->Run("other_address");$word->selection->TypeText($data4);$word->Application->Run("postalcode");$word->selection->TypeText($data5);?>[code=php:0] Link to comment https://forums.phpfreaks.com/topic/20056-php-msword-mysql/ Share on other sites More sharing options...
AndyB Posted September 7, 2006 Share Posted September 7, 2006 Just for the record, which is line 8 of your script? Link to comment https://forums.phpfreaks.com/topic/20056-php-msword-mysql/#findComment-88057 Share on other sites More sharing options...
proctk Posted September 8, 2006 Author Share Posted September 8, 2006 line 8$word->Document->open($userfile); Link to comment https://forums.phpfreaks.com/topic/20056-php-msword-mysql/#findComment-88089 Share on other sites More sharing options...
AndyB Posted September 8, 2006 Share Posted September 8, 2006 If the error occurs in ...familyclick/WordTest.php then the document name should be formtemplates/letter.doc i.e that looks like the correct address relative to a file in the folder familyclick. Link to comment https://forums.phpfreaks.com/topic/20056-php-msword-mysql/#findComment-88096 Share on other sites More sharing options...
proctk Posted September 8, 2006 Author Share Posted September 8, 2006 made the change and I still get the same error Link to comment https://forums.phpfreaks.com/topic/20056-php-msword-mysql/#findComment-88156 Share on other sites More sharing options...
redarrow Posted September 8, 2006 Share Posted September 8, 2006 $userfile = "familyclick/formtemplates/letter.doc"; Link to comment https://forums.phpfreaks.com/topic/20056-php-msword-mysql/#findComment-88219 Share on other sites More sharing options...
Jenk Posted September 8, 2006 Share Posted September 8, 2006 use realpath() for stability. Link to comment https://forums.phpfreaks.com/topic/20056-php-msword-mysql/#findComment-88230 Share on other sites More sharing options...
proctk Posted September 8, 2006 Author Share Posted September 8, 2006 how would I use realpath() Link to comment https://forums.phpfreaks.com/topic/20056-php-msword-mysql/#findComment-88397 Share on other sites More sharing options...
Jenk Posted September 8, 2006 Share Posted September 8, 2006 http://php.net/realpath Link to comment https://forums.phpfreaks.com/topic/20056-php-msword-mysql/#findComment-88494 Share on other sites More sharing options...
proctk Posted September 8, 2006 Author Share Posted September 8, 2006 I'm having no luck with this I get this errorFatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Word<br/><b>Description:</b> This file could not be found. Try one or more of the following: * Check the spelling of the name of the document. * Try a different file name. (letter.doc)' in C:\MyServer\xampp\htdocs\familyclick\WordTest.php:7 Stack trace: #0 C:\MyServer\xampp\htdocs\familyclick\WordTest.php(7): variant->Open('letter.doc') #1 {main} thrown in C:\MyServer\xampp\htdocs\familyclick\WordTest.php on line 7the file is stored in the root directory I'm confident that all is spelled correctly any tipsany pointers[code=php:0]<?php//1. Instanciate Word$word = new COM("word.application") or die("Unable to instantiate Word");//2. specify the MS Word template document (with Bookmark TODAYDATE inside)$template_file = realpath("letter.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 = "first_name";$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 = "reminder_new.doc";$word->Documents[1]->SaveAs($new_file);//8. free the object$word->Quit();$word->Release();$word = null;?>[/code] Link to comment https://forums.phpfreaks.com/topic/20056-php-msword-mysql/#findComment-88746 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.