SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 34
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with COM? (still not fixed!)

    I have the following script to generate a Microsoft Word file (actually it just fills in the bookmarks in template.doc):

    PHP Code:
    <?

    //1. Instanciate Word
    $word = new COM("word.application") or die("Unable to instantiate Word");
    //2. specify the MS Word template document
    $template_file "c:/avishai/php/manager/invoice/template.doc";
    //3. open the template document
    $word->Documents->Open($template_file);
    //4. put '734' in the 'id' bookmark
    $id 734;
    //5. get the bookmark and create a new MS Word Range (to enable text substitution)
    $bookmarkname "id";
    $objBookmark $word->ActiveDocument->Bookmarks($bookmarkname);
    $range $objBookmark->Range;
    //6. now substitute the bookmark with actual value
    $range->Text $id;
    //7. save the template as a new document (c:/reminder_new.doc)
    $new_file "c:/avishai/php/manager/invoice/test.doc";
    $word->Documents[1]->SaveAs($new_file);
    //8. free the object
    $word->Quit();
    $word->Release();
    $word null;

    ?>
    However, it produces the following error message:

    Warning: (null)(): Invoke() failed: Type mismatch. Argument: 2 in c:\avishai\php\manager\invoice\process.invoice.php on line 19

    And the file does not get produced.

    Any ideas???? Thanks in advance,

    Shai
    Last edited by shaiphp; Jun 5, 2005 at 12:07.

  2. #2
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well you're obviously using a third-party class, there is so many things that could be wrong here. You are best asking for support by the class author

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think I am using a third party class...I definitely haven't downloaded one so it must be built in to PHP.

  4. #4
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dean C
    Well you're obviously using a third-party class, there is so many things that could be wrong here. You are best asking for support by the class author
    He isn't using a third party class, Dean, he is using COM.

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for confirming, Dylan. I don't actually know how exactly my script communicates with MS Word, but it does!! I will look into how COM works at some point!

    The thing I forgot to mention was that when the script runs, I get a dialog box from Word asking if I want to save the current document before exiting. This would imply that the file IS changed, but it is then exited without doing the Save As. If I say 'Yes' on the dialog box, the file saves with the new content. However, I need it to Save As!

    In fact, I don't know if this makes it easier, but after the Word file is created I just need it to be attached to an email using mail() and then the file will be deleted! So it may be easier to just save the file somewhere temporary? I don't mind either way.

    Also, if you know of a tutorial that will tell me how to create and save Word documents then I will try that. RTF will do as well.

    Thanks so much and I hope you can help,

    Shai

  6. #6
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way, I am using PHP 4(.3.4). I have heard that PHP 5 uses slightly different OOP - could this be the problem? If so, how do I fix it? I do not want to upgrade to PHP 5 at this time.

  7. #7
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still not fixed - any more suggestions??

    Thanks

  8. #8
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What happens if you get rid of the
    PHP Code:
    $word null
    ?

  9. #9
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope - doing that makes no difference!

    I really appreciate your help and I hope we will be able to solve this problem,

    Shai

  10. #10
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Line 19 is
    PHP Code:
    $word->Documents[1]->SaveAs($new_file); 
    Yes?

  11. #11
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes

  12. #12
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where did you get this script from?

  13. #13
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  14. #14
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What happens if you get rid of the bookmark part? As in, just open, save, cleanup.

  15. #15
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Same problem

  16. #16
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    except that because you are not making any changes, the dialog box asking if you want to save changes doesn't pop up

  17. #17
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What OS are you running? What version of PHP? What version of Apache (or is it IIS)?

  18. #18
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Windows, PHP 4.3.4, Apache 1.3.29

  19. #19
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which version of Windows? Which version of Office?

  20. #20
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Windows 98SE, Office 97

  21. #21
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think Windows 98 supports COM. Actually, I don't think Office 97 does either. I'll see if I can confirm that, though.

  22. #22
    Non-Member
    Join Date
    May 2005
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very outdated software, I'm not suprised it isnt working!

  23. #23
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am pretty sure they do. Apart from anything else, when I click 'Yes' on the dialog box (to overwrite the template.doc file with the new content), it DOES work. The problem is that I can't save AS. So surely that means that COM is working?

  24. #24
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dale, do you have any contributions to make or just useless comments about my software??

  25. #25
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Give SaveAs a second parameter of 0, see if that works. I haven't see anyone use saveas without the second parameter.


Bookmarks

Posting Permissions

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