spersad Posted September 15, 2008 Share Posted September 15, 2008 I have a problem whereby I want to generate a word document from PHP using the COM libraries. The problem is that I want to output the results from a mysql query into MS word but I cant. Can someone please help me. Thanking you in advance Link to comment https://forums.phpfreaks.com/topic/124309-generate-word-documents-from-php/ Share on other sites More sharing options...
kenrbnsn Posted September 15, 2008 Share Posted September 15, 2008 Do you have any code you can post that demonstrates the problem? Ken Link to comment https://forums.phpfreaks.com/topic/124309-generate-word-documents-from-php/#findComment-641916 Share on other sites More sharing options...
spersad Posted September 15, 2008 Author Share Posted September 15, 2008 This is a sample of the code: In this code I am writing data to "BOOKMARKS" on a word document. I however want to write the results from a mysql query in the same manner but I do not know how to go about that because I am getting errors if i try to write the resultsl. Any help would be greatly appreciated try { $word = new COM("word.application") or die("Unable to instantiate Word"); $template_file = "C:\VertrigoServ\www\EMA\acktemplate.doc"; $word->Documents->Open($template_file); $word->Visible = 1; $current_date = date("m/d/Y"); $bookmarkname = "FILENUMBER"; $bookmarkname2 = "DATE"; $bookmarkname3 = "NAME"; $bookmarkname4 = "SUBJECT"; $bookmarkname5 = "ADDRESS"; $objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname); $objBookmark2 = $word->ActiveDocument->Bookmarks($bookmarkname2); $objBookmark3 = $word->ActiveDocument->Bookmarks($bookmarkname3); $objBookmark4 = $word->ActiveDocument->Bookmarks($bookmarkname4); $objBookmark5 = $word->ActiveDocument->Bookmarks($bookmarkname5); $range = $objBookmark->Range; $range2 = $objBookmark2->Range; $range3 = $objBookmark3->Range; $range4 = $objBookmark4->Range; $range5 = $objBookmark5->Range; $range->Text = $filenum; $range2->Text = $current_date; $range3->Text = $name; $range4->Text = $subject; $range5->Text = $address; $new_file = "c:/$filenum.doc"; $word->Documents[1]->SaveAs($new_file); //Write obj to db //8. free the object $word->Quit(); $word->Release(); $word = null; } Link to comment https://forums.phpfreaks.com/topic/124309-generate-word-documents-from-php/#findComment-641923 Share on other sites More sharing options...
aschk Posted September 19, 2008 Share Posted September 19, 2008 So does what you posted work? It looks like it should (assuming of course you have the COM lib available to PHP). So what do your MySQL queries look like? Because this appears to be the missing step. Link to comment https://forums.phpfreaks.com/topic/124309-generate-word-documents-from-php/#findComment-645493 Share on other sites More sharing options...
spersad Posted September 22, 2008 Author Share Posted September 22, 2008 I got through with the code. It was just a matter of creating a class. However does anyone know how to launch ms word from a hyperlink. This is the code i am using a href='file://......test.doc' target=_blank>test.doc</a>. However it opens the file in the browser. I want to launch the ms word document outside of the browser. Any help would be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/124309-generate-word-documents-from-php/#findComment-647651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.