[PHP-DEV] RE: PHP, Windows and COM.
hi richard The problem with some of the VBA functions is that the first and last parameter need to be set and the ones in the middle have no meaning and cannot be present. This can only be achieved by using named parameters. The GoTo method, as a function, in VBA would be ... sooner or later everything ends up in a native c(++) function call and there are no such things as named parameters. therefore nonpresent parameters will be assigned a default value (iirc NULL if no explicit default value is specified.) so try calling GoTo(wdGoToBookmark, NULL, NULL, BookmarkName); or, if it doesn't work $empty = new VARIANT(); GoTo(wdGoToBookmark, $empty, $empty, BookmarkName); the difference is, that there exists two different variant types with nearly the same meaning, VT_NULL and VT_EMPTY. PHP's NULL will be marshalled to VT_NULL, VT_EMPTY has to be created by explicitly creating an empty variant container in php. ad. your previous question: there are two other ways of importing a type library, you can either com_load_typelib(Word.Application) which will search for the typelib assigned to that component or you can enable com.autoregister_typelib in your php.ini which will cause php to load the typelib for every component you instanciate. harald -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] RE: PHP, Windows and COM.
Genius! Thank you very much. Can this example be added to the PHP Manual? All the online examples I've seen relate to functions which you can pass the first few params and no more. In this case having to pass the first and last param is not mentioned. This simple example demonstrates the use of php's VARIANT() type and now to call functions that use it. Thank you VERY much!! Regards, Richard. -Original Message- From: Harald Radi [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 26, 2003 10:41 AM To: 'Richard Quadling' Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: PHP, Windows and COM. hi richard The problem with some of the VBA functions is that the first and last parameter need to be set and the ones in the middle have no meaning and cannot be present. This can only be achieved by using named parameters. The GoTo method, as a function, in VBA would be ... sooner or later everything ends up in a native c(++) function call and there are no such things as named parameters. therefore nonpresent parameters will be assigned a default value (iirc NULL if no explicit default value is specified.) so try calling GoTo(wdGoToBookmark, NULL, NULL, BookmarkName); or, if it doesn't work $empty = new VARIANT(); GoTo(wdGoToBookmark, $empty, $empty, BookmarkName); the difference is, that there exists two different variant types with nearly the same meaning, VT_NULL and VT_EMPTY. PHP's NULL will be marshalled to VT_NULL, VT_EMPTY has to be created by explicitly creating an empty variant container in php. ad. your previous question: there are two other ways of importing a type library, you can either com_load_typelib(Word.Application) which will search for the typelib assigned to that component or you can enable com.autoregister_typelib in your php.ini which will cause php to load the typelib for every component you instanciate. harald -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] RE: PHP, Windows and COM.
Hi Harald. The problem with some of the VBA functions is that the first and last parameter need to be set and the ones in the middle have no meaning and cannot be present. This can only be achieved by using named parameters. The GoTo method, as a function, in VBA would be ... GoTo(wdGoToBookmark,,,BookmarkName) OLEView shows the GoTo method as ... [id(0x00ad), helpcontext(0x095e00ad)] HRESULT _stdcall GoTo( [in] VARIANT* What, [in, optional] VARIANT* Which, [in, optional] VARIANT* Count, [in, optional] VARIANT* Name, [out, retval, optional] Range** prop); I only want to supply What and Name, Which and Count are not valid for bookmarks. Is there a true NULL type I can send? Richard. P.S. Thanks for the OLEView pointer. -Original Message- From: Harald Radi [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 25, 2003 5:14 PM To: 'Richard Quadling'; [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: PHP, Windows and COM. hi richard, currently there is no way of calling a function with named arguments. your proposed array syntax wouldn't allow for passing arrays. on the other hand variant arrays can only be indexed arrays and not hash arrays so i could treat all string indices as named parameters. this would be a possibility though i still find it very confusing. if anybody has a good suggestion that is feasable on top of the engine (meaning without modifying the scanner/parser) don't hesitate to post it to the list. back to your actual problem: you still can call all functions without naming parameters, though you have to specify the full list of parameters up to at least the last optional parameter that should not be set to its default value (uuh, does this make sence ? actually its exactly the same as calling a php function with optional parameters). you can look up the default values for optional parameters in the components typelibrary which is browsable using the oleview tool. i hope that helps. -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] RE: PHP, Windows and COM.
hi richard, currently there is no way of calling a function with named arguments. your proposed array syntax wouldn't allow for passing arrays. on the other hand variant arrays can only be indexed arrays and not hash arrays so i could treat all string indices as named parameters. this would be a possibility though i still find it very confusing. if anybody has a good suggestion that is feasable on top of the engine (meaning without modifying the scanner/parser) don't hesitate to post it to the list. back to your actual problem: you still can call all functions without naming parameters, though you have to specify the full list of parameters up to at least the last optional parameter that should not be set to its default value (uuh, does this make sence ? actually its exactly the same as calling a php function with optional parameters). you can look up the default values for optional parameters in the components typelibrary which is browsable using the oleview tool. i hope that helps. regards, Harald Radi -- nme - we can heal you http://www.nme.at http://www.nme.at/ Ortner Radi Schwenk GnbR Tumpenweg 528 5084 Grossgmain, Salzburg Austria -Original Message- From: Richard Quadling [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 25, 2003 5:53 PM To: '[EMAIL PROTECTED]'; '[EMAIL PROTECTED]'; '[EMAIL PROTECTED]'; '[EMAIL PROTECTED]' Subject: PHP, Windows and COM. Hi. As authors of the COM.c within the PHP Source code, I am hoping one of you clever people can help me. I am trying to use PHP to control MS Word. Simple stuff like opening a document, writing and saving I have no problem with, and many of the online tutorials on this show this and very little else. My problem is that I want to use functions from within Word where the parameters would be named. e.g. In VBA, the GoTo function is defined as; expression.GoTo(What, Which, Count, Name) The following examples are all valid. Selection.GoTo What:=wdGoToHeading, Which:=wdGoToFirst Selection.GoTo What:=wdGoToHeading, Which:=wdGoToAbsolute, Count:=1 Selection.GoTo What:=wdGoToField, Name:=Date The What parameter can be ... wdGoToBookmark wdGoToComment wdGoToEndnote wdGoToEquation wdGoToField wdGoToFootnote wdGoToGrammaticalError wdGoToGraphic wdGoToHeading wdGoToLine wdGoToObject wdGoToPage wdGoToPercent wdGoToProofreadingError wdGoToRevision wdGoToSection wdGoToSpellingError wdGoToTable The Which parameter can be ... wdGoToAbsolute wdGoToFirst wdGoToLast wdGoToNext wdGoToPrevious wdGoToRelative All the parameters are optional. Not all work together. For example, you can't say goto the page named fred as pages don't have names! The problem I have within PHP is I can't work out how to use any function that has optional parameters. e.g. $word-Documents[1]-GoTo(array(What=wdGoToBookmark,Name=YourName)); $word-Documents[1]-GoTo(wdGoToBookmark,YourName); etc. The function seems to have been defined as requiring 4 parameters from PHP's pov. Is there any known method within PHP to support named parameters for COM functions that have optional parameters. Search and Replace is another one I can get working, which is why I tried using bookmarks, but still no joy. Now, if I've lost the plot, then let me know. Alternatively/also, how do I know what typelibrary to load? Is ... com_load_typelib(C:\\Program Files\\Common Files\\Microsoft Shared\\Office10); correct when ... ?php set_time_limit(0); error_reporting(E_ALL); com_load_typelib(C:\\Program Files\\Common Files\\Microsoft Shared\\Office10); $word = new COM(word.application) or die(Unable to create Word); print Loaded Word, version {$word-Version}\n; $word-Documents-Open(C:\\Empty.DOC); print Document loaded; $word-Documents[1]-GoTo(array(What=-1,Name=YourName)); print Goto 1 done; $word-Selection-TypeText({$_GET['YourName']}); print Typetext 1 done; $word-Documents[1]-GoTo(array(What=-1,Name=YourAge)); print Goto 2 done; $word-Selection-TypeText({$_GET['YourAge']}); print Typetext 2 done; $word-Documents[1]-SaveAs(C:\\filled.doc); print New saved document; $word-Quit(); $word-Release(); $word = null; print Word closed.\n; ? The word document has 2 bookmarks. I called YourName and one called YourAge. The above script is called as word.php?YourName=RichardYourAge=35 Please help! Regards, Richard Quadling