Get content from ms word

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
p_h_p
Forum Newbie
Posts: 7
Joined: Tue Mar 16, 2004 4:11 am

Get content from ms word

Post by p_h_p »

Hi,
I want to create php page that gets all the content from ms word file. It means i want to publish word content directly into php page...Can someone please help me...thanks....
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

ARe you running on a windows or unix sever?

Only possible on windows using the COM functions

Mark
p_h_p
Forum Newbie
Posts: 7
Joined: Tue Mar 16, 2004 4:11 am

Post by p_h_p »

I running on windows, then i have config the COM in the php.ini...But may i know how the codes look like? thanks.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

p_h_p
Forum Newbie
Posts: 7
Joined: Tue Mar 16, 2004 4:11 am

Post by p_h_p »

Code: Select all

<?
$input = "Appendix_5___Interim_Report.doc";  
$word = @new COM("word.application") or die("Unable to instantiate Word"); 
print "Loaded Word, version {$word->Version}\n<br>"; 
$word->Visible = 1; 
print "Set Word To Visible<br>"; 
$word->Documents->Open($input); 
print "Opened $input<br>"; 
$word->Activate; 
print "Activated Word<br>"; 

print "Editing Fields<br>"; 
$Field = $word->ActiveDocument->Fields(1); 
$fieldData = $Field->Result; 
$fieldData->Text = "Testing"; 

// Print the document. 
$word->Printout(); 

// closing word 
$word->Quit(); 

// free the object 
$word->Release(); 
$word = null; ?>
I have try tis code but it take v.long to load....is there aniting wrong with the codeS?thank..
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

No nothing wrong with it, it's just that it takes a long time to load Word.

Mark
p_h_p
Forum Newbie
Posts: 7
Joined: Tue Mar 16, 2004 4:11 am

Post by p_h_p »

But now the problem is it only load half way and it stop already...
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

How large is the final your loading?
alucard
Forum Newbie
Posts: 3
Joined: Wed Mar 17, 2004 5:49 am

Post by alucard »

Check your max allowable execution time for a script on php.ini
p_h_p
Forum Newbie
Posts: 7
Joined: Tue Mar 16, 2004 4:11 am

Post by p_h_p »

The word file is only 20kb, and ytdae i have try it oso...it did not load for so long but have errors on

1) $Field = $word->ActiveDocument->Fields(1);

2) $word->Printout();
Post Reply