I am trying to use PHP's COM support to open a URL from within MS Word
then save the document.
I am using PHP5.0.3/Apache2/WindowsXP. phpinfo() confirms that COM support
is enabled.
Manually, this would be:
- Start MS Word (am using Office 2003)
- File > Open
- Enter a URL and click Open
- File > Save As...
- Save the file then close MS Word.
Does anyone know the COM syntax used in PHP to open a URL (rather than a
file) with Word?
Using
$this->handle->Documents->Open('http://www.example.com/page/');
seems not to work.
I have tried two approaches, neither of which work.
1) The posting at
http://uk.php.net/com made at
03-Jun-2004 07:37
Using example 1, but changing the input to a URL rather than a file (as
above).
2) The posting at
http://www.phpbuilder.com/lists/php-...03082/0067.php
suggests that the following outght to work:
$word=new COM("Word.Application") or die("Cannot start word for you");
$word->visible = 0;
$word->Options->ConfirmConversions = false; // menu:
options->general->confirm conversions
// search for HTML Converter
$fcList = $word->FileConverters();
$count = $fcList->Count();
for($i=1; $i<=$count; $i++) {
$fc = $fcList->Item($i);
// go for ClassName, it's locale-independent
if ($fc->ClassName() == 'HTML') break;
}
if ($i <= $count) {
$word->Documents->Open ($inputUrl, False, False, False, '', '', False, "", "", $fc->OpenFormat());
$word->Documents[1]->SaveAs($outputWordFile, wdFormatDocument);
$word->Document[1]->Close();
$word->Quit();
$word->Release();
}
but it does not. The script runs, but causes zero errors (error_reporting
is set to 2047), yet does not output any file.
Any suggestions?
Martin