PHP COM class missing...
I am using a script to process a Word template with bookmarks in the Drupal files directory and save it as a new file.
But when I run it (within a Drupal 6.4 site with PHP 5.2.6) I get an error that the COM class is not found. I tried the older com_load method too, same error.
I looked at phpinfo, didn't see any COM class there-
Is there another way to create a Word doc with preset content in a two-column table format?
[EDIT]
There are two main ways to build Excel, Word, and PowerPoint documents using PHP. The first is by using the COM library (only if you are using a Windows server) and the other is by using a more standardized approach such as HTML or CSV.
<?php
//1. Instantiate 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 = "termplates/laptop_template.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 = "date";
$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 = "files/form_submissions/laptop_template.doc";
$word->Documents[1]->SaveAs($new_file);
//8. free the object
$word->Quit();
$word->Release();
$word = null;
?>
Attachment | Size |
---|---|
508_phpinfo.jpg | 726.56 KB |