Page 1 of 1

Reading Word 2007 Files

Posted: Mon Sep 07, 2009 4:27 pm
by Gobro
Hello,

I'm trying to read some .doc or .docx files or make any contact with word 2007 but so far i'm getting nothing, i tried to get it working even used the example code from php.net but it still refuses to work with word, i don't know why.

The example code from php.net

Code: Select all

<?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;
?>
Fatal error: Call to undefined method variant::SaveAs()
or
Fatal error: Call to undefined method variant::Quit()

Also tried

Code: Select all

$content = (string) $word->ActiveDocument->Content;
echo $content;
And various stuff with

Code: Select all

$word->ActiveDocument
$word->Documents[1]
$word->Documents[0]
$word->Documents
All i'm getting is function not found or an infinite time loop until i kill the word process... :(

Re: Reading Word 2007 Files

Posted: Tue Sep 08, 2009 5:44 pm
by Gobro
Anyone?

Re: Reading Word 2007 Files

Posted: Tue Sep 08, 2009 5:51 pm
by Eran
I would suggest against using COM objects, it would only work on windows servers. It is also somewhat tedious to use. We use AbiWord http://www.abisource.com/ which is an open-source solution for reading / converting word documents into many formats (including HTML).

Re: Reading Word 2007 Files

Posted: Thu Sep 10, 2009 8:59 am
by Gobro
It's not even on a server i'm trying it on my local machine and i just want to read some words docs... :(

Re: Reading Word 2007 Files

Posted: Sun Sep 13, 2009 2:10 pm
by Gobro
Thanks a lot for not replying everyone...
Switched to TXT files.

Re: Reading Word 2007 Files

Posted: Sun Sep 13, 2009 2:15 pm
by phaeton
I though pytrin reply was quite informative. He mentnioned using COM objects but that will only work on a Windows machine.

I'm glad you've found a solution that works for you.