Using COM to Open Word

I am really trying to use some codes found by me 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 am getting the following:

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

Can anyone solve this problem? Is it because I use Word 2007?

+3
source share
3 answers

I solved this using: http://www.phpbuilder.net/columns/venkatesan20030501.php3 ? thank you for your responses

+1
source

Documents - Collection, . :

$word->Documents(1)->SaveAs("Useless test.doc");

$word->ActiveDocument->SaveAs("Useless test.doc");
+1

, Word 2003, Word 2007 7. , / Word. :

  • Word
  • , Word , script
  • %APPDATA%\Microsoft\Templates\ Normal.dot(x)
  • , ,
+1

Source: https://habr.com/ru/post/1738360/


All Articles