0

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;
?>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by jkon
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.