note 29830 added to class.variant
| From: | richard dot quadling at carval dot co dot uk | Date: | Wed, 26 Feb 2003 11:50:42 +0000 |
| Subject: | note 29830 added to class.variant | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44548@lists.php.net to get a copy of this message | ||
With thanks to Harald Radi and Wez Furlong.
Some VBA functions have optional parameters. Sometimes the parameters you want to pass are not
consecutive.
e.g.
GoTo What:=wdGoToBookmark, Name="BookMarkName"
GoTo(wdGoToBookmark,,,"BookMarkName)
In PHP, the "blank" parameters need to be empty.
Which is ...
<?php
// Some servers may have an auto timeout, so take as long as you want.
set_time_limit(0);
// Show all errors, warnings and notices whilst developing.
error_reporting(E_ALL);
// Used as a placeholder in certain COM functions where no parameter is required.
$empty = new VARIANT();
// Load the appropriate type library.
com_load_typelib('Word.Application');
// Create an object to use.
$word = new COM('word.application') or die('Unable to load Word');
print "Loaded Word, version {$word->Version}\n";
// Open a new document with bookmarks of YourName and YourAge.
$word->Documents->Open('C:/Unfilled.DOC');
// Fill in the information from the form.
$word->Selection->GoTo(wdGoToBookmark,$empty,$empty,'YourName'); // Note use of
wdGoToBookmark, from the typelibrary and the use of $empty.
$word->Selection->TypeText($_GET['YourName']);
$word->Selection->GoTo(wdGoToBookmark,$empty,$empty,'YourAge');
$word->Selection->TypeText($_GET['YourAge']);
// Save it, close word and finish.
$word->Documents[1]->SaveAs("C:/{$_GET['YourName']}.doc");
$word->Quit();
$word->Release();
$word = null;
print "Word closed.\n";
?>
The example document is ...
Hello [Bookmark of YourName], you are [Bookmark of YourAge] years old.
and it would be called ...
word.php?YourName=Richard%20Quadling&YourAge=35
Regards,
Richard.
--
http://www.php.net/manual/en/class.variant.php
http://master.php.net/manage/user-notes.php?action=edit+29830
http://master.php.net/manage/user-notes.php?action=delete+29830
http://master.php.net/manage/user-notes.php?action=reject+29830