Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Creating Word Document Error

    I got this error while trying to create a word document.

    Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Word<br/><b>Description:</b> The requested member of the collection does not exist.' in C:\xampplite\htdocs\print_short_list.php:25 Stack trace: #0 C:\xampplite\htdocs\print_short_list.php(25): unknown() #1 {main} thrown in C:\xampplite\htdocs\print_short_list.php on line 25


    Line 25 is...
    $word->Documents[0]->SaveAs($filename);

    Here is the entire code

    PHP Code:
    <?php

    $word 
    = new COM("word.application");

    $word->Visible 0;

    $word->Documents->Add();

    $word->Selection->PageSetup->LeftMargin '2';
    $word->Selection->PageSetup->RightMargin '2';

    $word->Selection->Font->Name 'Arial';
    $word->Selection->Font->Size 10;

    $word->Selection->TypeText("TEXT!");

    // Save document
    $filename tempnam(sys_get_temp_dir(), "word");
    $word->Documents[0]->SaveAs($filename);

    $word->quit();
    unset(
    $word);

    header("Content-type: application/vnd.ms-word");
    header("Content-Disposition: attachment;Filename=document_name.doc");

    readfile($filename);
    unlink($filename);

    ?>

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,436
    Thanks
    13
    Thanked 360 Times in 356 Posts
    in the manual they always use $word->Documents[1]->SaveAs($filename);
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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