i want to edit certain bookmarks in a word document through PHP.
i bookmarked the relevant characters in the word document format.doc and run the following script....but its showing errors. Please help

<?php
$word = new COM("word.application") or die("Unable to instantiate Word");

echo "Loaded Word, version {$word->Version}\n";
$template_file = "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/test/format.doc";

$word->Documents->Open($template_file);

$current_date = date("j-n-Y-G-i-s");
// curr_date is the bookmark name in the template
$bookmarkname = "curr_date"; 
$objBookmark = $word->ActiveDocument->Bookmarks($bookmarkname);
$range = $objBookmark->Range;

$range->Text = $current_date;

$new_file = "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/test/format.doc";
$word->Documents[1]->SaveAs($new_file);

$word->Quit();
$word->Release();
$word = null;
?>

You created an instance of a Word application shouldn’t you also create an instance of Word Document Object too? What are the errors ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.