locked
PHP and Word? RRS feed

  • Question

  • Is there a forum where I can get this question answered? "Hi, is it possible to programmatically create .dot template files through a scripting language (PHP)?"
    Monday, April 11, 2011 5:14 PM

Answers

  • Create word.php to form a component which has methods to write MS word files.

    And use test.php to call such methods to create doc file programmatically.

     

    word.php 

     

    <?php

    class word

    { 

    function start()

    {

    ob_start();

    print'<html xmlns:o="urn:schemas-microsoft-com:office:office"

    xmlns:w="urn:schemas-microsoft-com:office:word"

    xmlns="http://www.w3.org/TR/REC-html40">';

    }

     

    function save($path)

    {

     

    print "</html>";

    $data = ob_get_contents();

     ob_end_clean();

    $this->wirtefile ($path,$data);

    }

     

    function wirtefile ($fn,$data)

    {

     $fp=fopen($fn,"wb");

    fwrite($fp,$data);

    fclose($fp);

    }

     }

     ?>

     

    test.php 

     

     <?php

    include("word.php");

    $word=new word;

    $word->start();

    ?>

     

     

    <?

    $word->save("data.dot");                    //save your dot file and exit  

    ?> 


    Kun Li

    Tier 2 Application Support

    Server and Tools Online Operations Team

    Tuesday, April 12, 2011 12:32 AM
  • For general questions about Word's DOM, visit http://social.msdn.microsoft.com/Forums/en-US/worddev/threads

    You need to find a PHP forum if you need help in general OLE programming that is not specific to Word.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Wednesday, April 13, 2011 6:09 PM

All replies

  • Hi, BrianK

     

    Thank you for your post!

    I’m convinced that issues on PHP should not be posted in MSDN or TechNet forums.

    I have a personal solution to your problem, which I hope would work.

    You can check my next reply… 

     


    Kun Li

    Tier 2 Application Support

    Server and Tools Online Operations Team


    Tuesday, April 12, 2011 12:25 AM
  • Create word.php to form a component which has methods to write MS word files.

    And use test.php to call such methods to create doc file programmatically.

     

    word.php 

     

    <?php

    class word

    { 

    function start()

    {

    ob_start();

    print'<html xmlns:o="urn:schemas-microsoft-com:office:office"

    xmlns:w="urn:schemas-microsoft-com:office:word"

    xmlns="http://www.w3.org/TR/REC-html40">';

    }

     

    function save($path)

    {

     

    print "</html>";

    $data = ob_get_contents();

     ob_end_clean();

    $this->wirtefile ($path,$data);

    }

     

    function wirtefile ($fn,$data)

    {

     $fp=fopen($fn,"wb");

    fwrite($fp,$data);

    fclose($fp);

    }

     }

     ?>

     

    test.php 

     

     <?php

    include("word.php");

    $word=new word;

    $word->start();

    ?>

     

     

    <?

    $word->save("data.dot");                    //save your dot file and exit  

    ?> 


    Kun Li

    Tier 2 Application Support

    Server and Tools Online Operations Team

    Tuesday, April 12, 2011 12:32 AM
  • Hope that would be helpful.

    Have a great day!

    Thanks


    Kun Li

    Tier 2 Application Support

    Server and Tools Online Operations Team

    Tuesday, April 12, 2011 12:33 AM
  • For general questions about Word's DOM, visit http://social.msdn.microsoft.com/Forums/en-US/worddev/threads

    You need to find a PHP forum if you need help in general OLE programming that is not specific to Word.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Wednesday, April 13, 2011 6:09 PM