0

I have a ms word file with few texts, is there any way to add few texts in it using php code.

for instance, I have a word file and it has text like 'My name is.....', i would like to add one name in the dotted place using php code. enter image description here

1
  • 1
    Take a look at libraries like PHPWord Commented Sep 26, 2014 at 16:11

1 Answer 1

2

You would need to use Libraries like PHPWORD.It provides a set of classes to write to and read from different document file formats. You can also use phpLiveDocx which is a Zend Framework component and can read and write DOC and DOCX files in PHP on Linux, Windows and Mac. A sample code to do this with PHP COM

<?php 
// Create COM instance to word 

       function clsMSWord($Visible = false) 
   { 
       $this->handle = new COM("word.application") or die("Unable to instanciate Word"); 
       $this->handle->Visible = $Visible; 
   } 

function WriteHyperlink($Bookmark,$Path,$Text) 
   { 
           $objBookmark = $this->handle->ActiveDocument->Bookmarks($Bookmark); 
           $range = $objBookmark->Range; 
           $objHyperlink = $this->handle->ActiveDocument->Hyperlinks; 
           $objHyperlink->add($range,$Path,"","",$Text); 

   } 
Sign up to request clarification or add additional context in comments.

4 Comments

this would be a comment, which is already posted by MarkBaker on the question long before your answer. Please delete this and upvote the comment saying the same thing as your answer...
@FélixGagnon-Grenier see i have reeditted my answer..i think now you should remove the downvote
Add some code sample with how to do it and I'll surely upvote it :)
@FélixGagnon-Grenier now check i have given the code to do it with com CLASS..:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.