tags:

views:

24

answers:

2

I'm trying to use PHP COM to save docx files as html using Word. I am using a Windows installation with apache 2.2.x and PHP5. Office 2007 is installed.

Using the following code to list fileconverters:

$word = new COM('word.application') or die('Unable to instantiate word.');
foreach($word->FileConverters as $converter) {
    var_dump($converter->ClassName);
}

However, I only get the following output:

string(6) "wks632"
string(7) "Recover"
string(11) "WrdPrfctDos"
string(13) "WordPerfect6x"
string(14) "MSWinWrite.wpc"
string(11) "MSWord6.wpc"
string(11) "MSWorksWin6"

This microsoft document says there should be a 'HTML' option available. It may be for an older version of Office though, I am not sure!

Anyone know what's going on? Is it even possible to do this with my current setup?

A: 

As far as I can tell, there are a number of pre-defined converter names (of which HTML is one) and the list provided by the FileConverters object is a list of additional converters.

Mark Baker
+2  A: 

The objects that are listed in the FileConverters are only the converters that are using Word's RTF converter interface.

Word has additional built-in support for a variety of file formats which are described by the WdSaveFormat enumeration. To save as HTML, you could use the following code:

<?php
    $word->Documents->Add();
    $word->ActiveDocument->Range->Text = "Hello World!";
    $word->ActiveDocument->SaveAs('document.html', 8);
    $word->Quit();
?>
0xA3
Call to undefined method variant::SaveAs(). Same goes for Documents[0], Documents[1], Documents(0), or Documents(1) instead of ActiveDocument :(
Daniel
@Daniel: Are you sure that Word is installed? Note that VBA programmability must be selected during setup.
0xA3
@0xA3, yes, Word is installed... Heck, I can even get the same thing to work when I use a little vbs script. PHP just keeps whining about SaveAs not existing.
Daniel
@Daniel: Do you have multiple versions of Word installed on the same machine?
0xA3
@0xA3: Nope, it's a clean Windows XP install with Office 2007. It's weird because pretty much the same code translated to VBS works just fine. And most of the PHP COM statements work fine too.... Except for SaveAs.
Daniel
Got a different Office 2007 CD from my coworker. Works fine now, looks like it really was my install. Accepted for making me suspect that it might be a faulty installation :P
Daniel