Jump to content

Archived

This topic is now archived and is closed to further replies.

proctk

php msword mysql

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]

Share this post


Link to post
Share on other sites
Just for the record, which is line 8 of your script?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.