Converting HTML content to word doc using PHP code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • telgy
    New Member
    • Nov 2007
    • 1

    #1

    Converting HTML content to word doc using PHP code

    Hi,

    I want to Convert a HTML content to word doc using PHP code. pls help
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi. Welcome to TSDN!

    The simplest way to create a Word document is to simply use the Filesystem Functions to create a .doc file containing HTML markup.

    The other, slightly more complex way, is to use COM objects to create an actual Word Document. In order for this method to work, you need to have Word installed on the server. Then you can do something like this:
    [code=php]
    <?php
    # Create a Word object
    $word = new COM("word.appli cation") or die ("Couldn't create a Word object");
    $word->visible = 1;

    # Create a document and add some text
    $word->Documents->Add();
    $word->Selection->TypeText("Th is document was created in PHP!");

    # Save the document and release the Word object
    $word->Documents[1]->SaveAs("sample word.doc");
    $word->Quit();
    $word->Release();
    $word = null;
    ?>
    [/code]
    Note that Microsoft recommends against using Office in this manner. See this article for more on that.

    The last and most complex method would be to create your own Word parser. To do this you would need pretty detailed info on the inner workings of a Word Document.

    Comment

    • pwiegers
      New Member
      • Nov 2007
      • 1

      #3
      Hi,

      Originally posted by Atli
      The last and most complex method would be to create your own Word parser. To do this you would need pretty detailed info on the inner workings of a Word Document.
      I've often wondered about a 4th way: create OO.o XML (this should be relatively easy), and then callling OpenOffice to re-save the XML as .doc I've never gotten around to trying this, but it should not be hard..
      It would, I think, be the easiest way if you want extensive formatting in .doc....

      Anybody tried this?

      greetz,

      Paul

      Comment

      Working...