Jump to content

php msword mysql


proctk

Recommended Posts

Hi

I'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: etc

but get the same error


error

Fatal 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
Share on other sites

I'm having no luck with this I get this error

Fatal 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 7

the file is stored in the root directory I'm confident that all is spelled correctly

any tips

any 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.