PHP+ COM + MS Word

A

Anonymous

Guest
ok. I have this piece of code, but

Code:
$word = new COM("word.application");
$word->Visible=true;
$word->Documents->Open($fileName);
$word->Selection->TypeText("testing");
$word->Documents->Save();
$word->Documents->Close();
$word->Quit(true,false,false);

but gives me this error, any clues?

Fatal error: Uncaught exception 'com_exception' with message 'Unable to lookup `Visible': Access is denied. ' in d:\Inetpub\wwwroot\quejas\imprimirQueja.php:13 Stack trace: #0 d:\Inetpub\wwwroot\quejas\imprimirQueja.php(13): unknown() #1 {main} thrown in d:\Inetpub\wwwroot\quejas\imprimirQueja.php on line 13

and if i coment that row out, it will give me the same for the next one (Documents)
 
On which plateform you have implemented this code.

Linux or Windows?
 
Vikas: a bit weird question
Please be more carefull when you read messages:

d:\Inetpub\wwwroot\quejas\imprimirQueja.php

I think that will answer your question :)
if not: WINDOWS
and most probably on IIS but may be apache with standard IIS path...
 
Alexei, You are right. I must read the message carefully before making reply.

Thanks a lot for correcting & improving me.
 
well, yes, it's on Windows. but what about the problem at hand? any clues?
 
not really... 'Visible' access is denied..
WEIRD! i wonder if it has been set to Private...
but no..that shouldgive the error... is the file hyou are trying to use open?
if word is using it it might be a problem..
 
I guess you are trying to do the following:

Code:
<?php
// starting word
$word = new COM("word.application") or die("Unable to instantiate Word");
echo "Loaded Word, version {$word->Version}\n";

//bring it to front
$word->Visible = 1;

//open an empty document
$word->Documents->Add();

//do some weird stuff
$word->Selection->TypeText("This is a test...");
$word->Documents[1]->SaveAs("Useless test.doc");

//closing word
$word->Quit();

//free the object
$word = null;
?>
 
yea, but I want to open a document and change some fields with data from a db, i tried your code and It worked, but I changed it like this and it hangs

Code:
<?
  $word = new COM("word.application") or die("Unable to instantiate Word");
  echo "Loaded Word, version {$word->Version}\n";
  //bring it to front
  $word->Visible = 1;
  //open an empty document
  $word->Documents->Open("D:/Inetpub/wwwroot/quejas/quejas/q 1 2005.doc");
  //do some weird stuff
  $word->Selection->TypeText("This is a test...");
  $word->Documents[1]->Save();
  //closing word
  $word->Documents[1]->Close();
  $word->Quit();
  //free the object
  $word = null; 
?>
 
Back
Top