Friday, January 31, 2014

PHP - Export Content to MS Word document



The following PHP code to export content in MS Word document.
 <?php
 $doc_body ="
 <h1>PHP - Export Content to MS Word document</h1>
 <p>This is a test.<p>
 <p>This is a test.<p>
 ";
 ?>
 <form name="proposal_form" action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post"">
  <input type="submit" name="submit_docs" value="Export as MS Word" class="input-button" />
</form>
<?php
  if(isset($_POST['submit_docs'])){
          header("Content-Type: application/vnd.msword");
          header("Expires: 0");//no-cache
          header("Cache-Control: must-revalidate, post-check=0, pre-check=0");//no-cache
          header("content-disposition: attachment;filename=sampleword.doc");
  }         
          echo "<html>";
          echo "$doc_body";
          echo "</html>";      
?> 

video:Export Content to MS Word document


10 comments:

  1. Thanks for this code which is going to save my life. Please, how do you create a page break

    ReplyDelete
    Replies
    1. Jiansen Lu'S Computing Blog: Php - Export Content To Ms Word Document >>>>> Download Now

      >>>>> Download Full

      Jiansen Lu'S Computing Blog: Php - Export Content To Ms Word Document >>>>> Download LINK

      >>>>> Download Now

      Jiansen Lu'S Computing Blog: Php - Export Content To Ms Word Document >>>>> Download Full

      >>>>> Download LINK 6J

      Delete
  2. thanks for the code, but i gonna to how some sql query in the doc_body, how is the syntax to write php code inside the doc_body?

    ReplyDelete
  3. when i click export button word doc generated and this should be attached to email. is it possible ?

    ReplyDelete


  4. A great content and very much useful to the visitors. Looking for more updates in future.

    Selenium Training in Chennai

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. i wrote the same code. when i download the file on mobile it is working fine but that downloaded file is shown as currepted file and not open

    ReplyDelete