Search code examples
phpcomword-2007

Using COM to open Word


I am actually trying some codes i found from http://php.net/manual/en/class.com.php

  <?php
    // starting word
    $word = new COM("word.application") or die("Unable to instantiate Word");
    echo "Loaded Word, version {$word->Version}\n";

    //bring it to front
    $word->Visible = 1;

    //open an empty document
    $word->Documents->Add();

    //do some weird stuff
    $word->Selection->TypeText("This is a test...");
    $word->Documents[1]->SaveAs("Useless test.doc");


    //closing word
    $word->Quit();

    //free the object
    $word = null;
    ?> 

But this does not seem to work. I am using Word 2007 and i get the following:

Loaded Word, version 12.0 Fatal error: Call to undefined method variant::SaveAs() in C:\xampp\htdocs\final\testq.php on line 14

Can anyone solve this problem? Is it because i am using Word 2007?


Solution

  • I solved it by using : http://www.phpbuilder.net/columns/venkatesan20030501.php3? Thanks for your replies