Using COM to create Word doc
Posted: Tue Jun 03, 2008 3:00 am
OK, without using the code in red I am able to take the name from the form, place it in the Word template and save the file under a new name. When I try 2 fields as shown below, Word initiates but hangs and will not complete the process. I know the problem is where the red code is, maybe someone familiar with the Bookmark process in the COM object will help me out.
Code: Select all
<?php
$input = "C:/test.doc";
$name = $_POST['name'];
[color=#FF0000]$companyname = $_POST['companyname'];[/color]
$word = @new COM("word.application") or die("Unable to instantiate Word");
$word->Visible = 1;
$word->Documents->Open($input);
$bookmarkname = 'text45';
$objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
$range = $objBookmark->Range;
$range->Text = "$name";
[color=#FF0000]$bookmarknamea = 'text49';
$objBookmarka = $word->ActiveDocument->Bookmarks($bookmarknamea);
$rangea = $objBookmarka->Range;
$rangea->Text = "$companyname";[/color]
$new_file = "C:/$companyname.doc";
$word->Documents[1]->SaveAs($new_file);
$word->Quit();
$word = null;
?>