Jump to content

Generate Word Documents From PHP


spersad

Recommended Posts

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;

}

 

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

Archived

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

×
×
  • 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.