Page 1 of 1

COM, Office 2003 and Windows 2003 Server

Posted: Tue Jun 13, 2006 5:08 am
by dado
Pimptastic | 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 cannot make COM working with Office in my server. I think it is an authorization problem. Every time I run a simple script as:

Code: Select all

<?php

$word = new COM("word.application") or die("Non sono riuscito ad eseguire Word");
echo "Word caricato, versione {$word->Version}\n";

$word->Visible = 1;

$word->Documents->Add();

$word->Selection->TypeText("Questa è una prova...");
$word->Documents[1]->SaveAs("Prova inutile.doc");

$word->Quit();

$word->Release();
$word = null;
?>
nothing happen, word is not starting at all and php stucks. I have followed this article suggestions (Interfacing With COM Objects Under Windows):

http://www.phpbuilder.com/columns/venka ... hp3?page=1

but with no success. I have seen similar threads on this forum and somewhere else, but no one was containing an answer. I have installed php with easyphp, and in other machines with 2000 server I had no troubles, so I suspect is something related to Windows 2003 server.

Thank you for any possible reply


Pimptastic | 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]

Re: COM, Office 2003 and Windows 2003 Server

Posted: Tue Jun 13, 2006 8:52 am
by TheMoose
When you create a COM object, you don't pass it the file name you want, you pass it the application GUID or name, in this case, it would be Microsoft.Word

Code: Select all

<?php

$word = new COM("Microsoft.Word") or die("Non sono riuscito ad eseguire Word");
echo "Word caricato, versione {$word->Version}\n";

$word->Documents->Open("C:/prova.doc");

$word->Visible = 1;

$word->Documents->Add();

$word->Selection->TypeText("Questa è una prova...");
$word->Documents[1]->SaveAs("Prova inutile.doc");

$word->Quit();

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

Posted: Tue Jun 13, 2006 9:04 am
by dado
Thanks for Your reply TheMoose. Actually I have made a mistake typing te example in the forum. Now I have corrected it. I am using word.application, and I have tried microsoft.word as you suggest but with no success...