Hello, please sign in or register
You are here: Home

COM MS Office Edit MS Word

COM is a Microsoft product which lets applications like PHP connect to functions like reading, editing and printing, WORD, Excel documents. However i could not find much information on it I have created this script which will read the text content of a MS Word documnet(.doc). Including text within text box. Enjoy!

View written text content of .DOC file

// Connect to COM
$word = @new COM( "word.application" ) or die( "Unable to instanciate Word" );
// open file
 // view main content
$content = $word->ActiveDocument->Content->Text;
// Get content from textboxes
for($i = 1; $i <= $word->ActiveDocument->Shapes->Count; $i++){
$content .= chr(13).$word->ActiveDocument->Shapes[$i]->TextFrame->TextRange->Text;
// Clean up content
$content = str_replace(chr(7), "", $content);

// removes table carriage returns
$content = trim($content, chr(13));

// trims n carriage returns at the start and end of doc
$content = trim($content, chr(10)); // trims n carriage returns at the start and end of doc
$content = trim($content, chr(9)); // trims t carriage returns at the start and end of doc
$content = nl2br($content); // Replace n carriage returns with breaks
// Could have instead used
str_replace(chr(13), " ", $content);
//closing word
//free the object
$word = null;
return $content;

For linux, I found some links to implement another time.


But the replica watches sentry reebok shoes knew abercrombie and fitch uk his
Created 07/10/15
coach outlet online, http://www.coachoutletonline-store.us.com/
Created 15/10/15
ninest123 One canada goose pas cher gucci outlet thing
Created 21/07/16
michael kors factory outlet
adidas nmd pandora bracelet
Created 16/05/17

Prove you are not a robot

To prove you are not a robot, please type in the six character code you see in the picture below
Security confirmation codeI can't see this!
Email never shown*
Home Page


Andrew Dodson
Since:Feb 2007

Comment | flag


Bookmark and Share