Generate Microsoft Word (.doc) from php / asp

 

HOWTO Generate WORD Documents from PHP / ASP / .NET / JSP , ... 

Watch thoose websites for more informations :   



There are different ways to generate .doc files from PHP

 1. RTF Template

This is a simple and efficient way, as soon as you have a static Layout (I mean nothing to duplicate like lines of a table, ...) 

You can use an RTF template, and use regexp to replace strings :

Open WordPad (or word, or OOWriter, ...)

Create a file that looks exactly how you want, insert images if you want to, ... you're quite free.

And then instead of putting the title, the name of the user, ... insert stuffs like  **TITLE**  , **TEXT1** , **TEXT2** ,**USER_NAME**  ...

Save your RTF file as template.rtf (for example ...)

And in PHP use :

<?php

    $content= fil_get_contents('template.rtf'); 

     $content = str_replace('**TITLE**',$my_title,$content);

     $content = str_replace( '**USER_NAME**' , $my_username, $content); 

...

 ?>

And Voilà, $content is your new RTF file :) 

 


2. HTML Files 

The simpliest way, generate youre layout as HTML and send it to word as a .doc file. and it works :)

But You may experience problems with remote Images loading, ...


<?
    $fp 
fopen("test.doc"'w+');
    
$str "<html><body><B>This is the text for the word 

         file created through php programming</B></body></html>";

    
fwrite($fp$str);

    
fclose($fp);
?>

 

3. COM Objects 

You can use COM objects on Windows Servers  only



More solutions soon :)