Jump to content

problems with COM object for reading MS word.


epezhman

Recommended Posts

Hi, I'm trying to read a MS word doc, I found these code on a blog which uses COM , but when I run this PHP code I get an exception :

 

"

com_exception Object ( [message:protected] => Source: Microsoft Word

Description: The requested member of the collection does not exist. [string:Exception:private] =>

[code:protected] => -2147352567 [file:protected] => C:\wamp\www\PhpProject1\index.php [line:protected] => 31 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\wamp\www\PhpProject1\index.php [line] => 31 [function] => unknown ) ) [previous:Exception:private] => )

"
here is the code
$filename="cv.doc";
$TXTfilename = $filename . ".txt";

$word = new COM("word.application") or die("Unable to instantiate Word object");
$word->Documents->Open($filename);

// the '2' parameter specifies saving in txt format
$word->Documents[1]->SaveAs($TXTfilename ,2);
$word->Documents[1]->Close(false);
$word->Quit();
$word->Release();
$word = NULL;
unset($word);

$content = file_get_contents($TXTfilename);
unlink($TXTfilename);


 

 

I read from here  " http://ir2.php.net/manual/en/com.installation.php " that I don't need to install COM but I need to install some COM objects like for MS word doc, but I don't know how to fix it, any idea? thanks in advance :)

 

Link to comment
Share on other sites

here it is :

 

exception 'com_exception' with message 'Source: Microsoft Word

Description: The requested member of the collection does not exist.' in C:\wamp\www\PhpProject1\index.php:29 Stack trace: #0 C:\wamp\www\PhpProject1\index.php(29): unknown() #1 {main}

 

these line I guess :

$word->Documents[1]->SaveAs($TXTfilename ,2);

$word->Documents[1]->Close(false);

Link to comment
Share on other sites

i used similar coding to, but to add in some extra content to the word document using bookmarks. However, I commented out one line and it appeared to fix the problem for me - maybe it will work for you?

 

$word->Quit();

//$word->Release();

$word = null;

 

when i checked task manager afterwards I could see that word had exited correctly and ive not fully built a solution around what I intend to use this for so i dont know if there are any implications for doing this - maybe someone else will expand upon this?

Link to comment
Share on other sites

i used similar coding to, but to add in some extra content to the word document using bookmarks. However, I commented out one line and it appeared to fix the problem for me - maybe it will work for you?

 

$word->Quit();

//$word->Release();

$word = null;

 

when i checked task manager afterwards I could see that word had exited correctly and ive not fully built a solution around what I intend to use this for so i dont know if there are any implications for doing this - maybe someone else will expand upon this?

 

thanks for the reply .I tried it but it didn't work. I think it could't open the .doc file at all. when I write

echo count($word->Documents);

it just print 1, which means It doesn't open the doc file. I guess that create the COM application but can't open the the file. I tried it with different version of MS word and even windows OS but the same result. any more ideas? thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.