When upgrading our applications, the PHP Word COM no longer works.
Fatal error: Uncaught exception ‘com_exception’ with message ‘Source: Microsoft Word
Description: Command failed’
Has anyone successfully used word COM on any recent versions of these applications?
[php]<?php
//http://localhost/DotNetWordCom.php
//http://new-vcrm/DotNetWordCom.php
echo ‘
’;
echo “starting\n”;
set_time_limit (300); //to allow time for Word to load.
$word = new COM(“word.application”) or die (“Could not initialise MS Word object.”);
echo “COM instantiated\n”;
$word->Application->Visible = False;
echo “set visibility to false\n”;$doc = ‘sample.doc’;
$doc = ‘test.docx’;
$document = realpath($doc);
if(is_readable($document)) echo “Document exists and is readable \n”;
else if(!is_file($document)){ echo “Document does not exist\n”; die(); }
else{ echo “Document is not readable\n”; die(); }$word->Documents->Open( $document );
echo “Document opened\n”;
// Extract content.
$content = $word->ActiveDocument->Content;
echo “test\n----------\n”;
print_r($content);
echo “test\n----------\n”;
echo “Extracting string value of content\n”;
$content = (string) $content;
echo “test\n----------\n”;
echo $content;
echo “test\n----------\n”;echo $content;
$word->ActiveDocument->Close(false);
echo “Closed Document\n”;
$word->Quit();
echo “Quit Word \n”;
$word = null;
unset($word);
?>[/php]PHP - Version 5.3.8
Word 2007
Apache Version Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 mod_perl/2.0.4 Perl/v5.10.1
System: System Windows NT NEW-VCRM 6.1 build 7601 (Windows Server 2008 R2 Enterprise Edition Service Pack 1) i586