william007
william007

Reputation: 18525

editing word document using com

With the following code

<?php
$test="C:/wamp/www/test.doc";
com_load_typelib('Word.Application');
$word = new COM("word.application");
$word->Documents->Open($test);
$word->Visible = 1;
$word->ActiveDocument->FormFields("Text1")->Result = "test";
$word->ActiveDocument->Close(false);
$word->Quit();
unset($word);
?>

I get the following problem enter image description here

Line 7 is $word->ActiveDocument->FormFields("Text1")->Result = "test"; What is the problem?

Upvotes: 0

Views: 759

Answers (1)

Laurent Choulette
Laurent Choulette

Reputation: 331

We had the same problem with wamp on Windows 7. We finally solved the problem by performing the actions given in this php.net comment (although they are supposed to be useful for IIS) : http://php.net/manual/en/class.com.php#90814

I copy the main part here in case the original comment disappear :

  • Execute "dcomcnfg"
  • Open Component Services > Computers > My Computer > DCOM Config
  • Search for Microsoft Office Word 97-2003 Document (it will be something like this translated to your language, so take a while and search for it)
  • Right-Click on it and open the properties
  • Choose "Identity" tab
  • Normally this is set to "the launching user". You have to change this to "the interactive user" or a admin user of your choice.
  • Apply these new settings and test your COM application. It should work fine now.

Upvotes: 1

Related Questions