Jump to content


Photo

php msword mysql


  • Please log in to reply
9 replies to this topic

#1 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 07 September 2006 - 10:04 PM

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]

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 07 September 2006 - 11:49 PM

Just for the record, which is line 8 of your script?
Legend has it that reading the manual never killed anyone.
My site

#3 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 08 September 2006 - 12:40 AM

line 8

$word->Document->open($userfile);


#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 08 September 2006 - 12:59 AM

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.
Legend has it that reading the manual never killed anyone.
My site

#5 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 08 September 2006 - 03:24 AM

made the change and I still get the same error

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 08 September 2006 - 08:45 AM

$userfile = "familyclick/formtemplates/letter.doc";
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 08 September 2006 - 09:07 AM

use realpath() for stability.

#8 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 08 September 2006 - 02:14 PM

how would I use realpath()

#9 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 08 September 2006 - 04:34 PM

http://php.net/realpath

#10 proctk

proctk
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts

Posted 08 September 2006 - 11:20 PM

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


<?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;
?>







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users