Not signed in (Sign In)

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.


    • CommentAuthorviane
    • CommentTimeNov 7th 2006
     
    Dear All,

    I want to create report in Word Document with PHP and database MySQL.
    Anyone have example to write Word Document Using PHP?

    Thansk
    • CommentAuthorhardy
    • CommentTimeNov 7th 2006
     
    Here is the simplest method to write to a word file:


    <?
            $fp  =  fopen("amit.doc",  'w+');
            $str  =  "<B>This  is  the  text  for  the  word  file  created  through  php  programming</B>";

            fwrite($fp,  $str);

            fclose($fp);
    ?>


    if the above code is not enough then go to

    http://www.programmershelp.co.uk/phpcreateword.php
    • CommentAuthorviane
    • CommentTimeNov 7th 2006
     
    have PHP create excel file like this:
    <?php
    $word = new COM("word.application") or die ("couldnt create an instance of word");
    echo "loaded , word version{$word->version}";
    //bring word to the front
    $word->visible = 1;
    //open a word document
    $word->Documents->Add();
    //add some text to the document
    $word->Selection->TypeText("this is some sample text in the document");
    //save the document as sampleword.doc
    $word->Documents[1]->SaveAs("sampleword.doc");
    //close word
    $word->Quit();
    //free object resources
    $word->Release();
    $word = null;
    ?>


    But i want to format the content of Text. I want to change align, valign, and etc.
    How i do this?

    Thanks
    • CommentAuthorashmi
    • CommentTimeNov 7th 2006
     
    Hi,

    Hardy was right, you can create .doc files just with fopen() , naming it file_name.doc and putting in some html source and it works.
    To me it's far easier than using COM libraries.

    You can also create Excel file or any open office doc file just writing in some html souce and giving the right extention.

    You could also change the current document into a word file or a Excel file, no need to fopen and fputs try this simple test script to understand what I mean and check what does it look like :

    header("Content-Type:  application/vnd.ms-excel");
    print  "<table  border=\"1\"><tr><td><b>field1</b></td><td><b>field2</b></td></tr>";
    print  "<tr><td>value1  </td><td  bgcolor=\"#137799\">value2  in  blue  cell  bakground</td></tr></table>";  


    of course if you do a word file set the content-type to "application/msword" in header().
    And do what