Results 1 to 7 of 7

Thread: Creating an word doc from PHP/Mysql

  1. #1
    Join Date
    Apr 2008
    Posts
    43
    Rep Power
    0

    Default Creating an word doc from PHP/Mysql

    Hi all

    Do anyone know how to creat an word document using PHP. I have a form pulls data from a mysql database and display in the form. What i want to do is to have a button which will when click send the details of the user address and name from the form to a .doc word document.

    Anyone have any ideas of how this can me done?

  2. #2
    Join Date
    Jan 2008
    Posts
    5
    Rep Power
    0

    Default Creating a word document using PHP

    <?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;
    ?>

  3. #3
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default

    simpler to create a RTF file but either way you have to look up changing "content headers" in you php file

  4. #4
    Join Date
    Apr 2008
    Posts
    43
    Rep Power
    0

    Default

    thanks guys, would this script also carry the values from the form to the word doc? e.g. name, address fields?

  5. #5
    Join Date
    Jan 2008
    Posts
    5
    Rep Power
    0

    Default Creating a word document using PHP

    your objective can also be completed using this simple snippet.

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

    fwrite($fp, $str);

    fclose($fp);

  6. #6
    Join Date
    Feb 2006
    Posts
    4,242
    Rep Power
    0

    Default

    Did you accomplished the task successfully?
    |--- www.RealJamaicaEstate.com ™ ---|
    Invest small = small returns [micro enterprise] | Invest Big = returns Big [macro enterprise]
    --- www.fashionsJAMAICA.com ™ -|- www.ChampsJamaica.com

  7. #7
    Join Date
    Apr 2008
    Posts
    43
    Rep Power
    0

    Default

    yes got this done, thanks all for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •