MSWord and PHP
Posted: Thu Nov 16, 2006 3:05 pm
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have some PHP code which opens a Word doc and saves it as a different name. I'm trying to add code to find and replace a string in the document. Unfortunately, I find many references to Select.Find.Text, Selection.Find.Replacement.Text and Find.Execute but I can't figure out the correct syntax.Code: Select all
function SendDocumentToWord($Letter,$FileName)
{
echo "Starting";
$word=new COM("word.application") or die ("Unable to instanciate word");
$word->Visible=1;
$FullInputFilename="C:/inetpub/wwwroot/$Letter";
$FullOutputFilename="C:/inetpub/wwwroot/$FileName";
echo "opening $FullInputFilename";
$word->Documents->Open($FullInputFilename);
$word->Selection.FindText('mkp');
$word->Selection.ReplaceText('dog');
$word->Selection.Find.Execute();
echo "<BR>Saving as $FullOutputFilename...";
$word->Selection->TypeText(" replaced ");
$word->ActiveDocument->SaveAs($FullOutputFilename);
echo "Saved";
$word->Quit();
$word=null;
unset($word);
exit;feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]