Add hyperlink at a Word Document's bookmark
<?php
// Create COM instance to word
function clsMSWord($Visible = false)
{
$this->handle = new COM("word.application") or die("Unable to instanciate Word");
$this->handle->Visible = $Visible;
}
function WriteHyperlink($Bookmark,$Path,$Text)
{
$objBookmark = $this->handle->ActiveDocument->Bookmarks($Bookmark);
$range = $objBookmark->Range;
$objHyperlink = $this->handle->ActiveDocument->Hyperlinks;
$objHyperlink->add($range,$Path,"","",$Text);
}
?>
COM et .Net (Windows)
- Introduction
- Installation/Configuration
- Constantes pré-définies
- Erreur et gestion des erreurs
- Exemples
- Fonctions COM et .Net (Windows)
- COM — Classe COM
- DOTNET — La classe DOTNET
- VARIANT — classe VARIANT
- com_addref — Incrémente le compteur de références [Obsolète]
- com_create_guid — Génère un identifiant unique global (GUID)
- com_event_sink — Connecte des événements d'un objet COM sur un objet PHP
- com_get_active_object — Retourne un objet représentant l'instance actuelle d'un objet COM
- com_get — Lit la valeur d'une propriété d'un composant COM [Obsolète]
- com_invoke — Appelle une méthode d'un composant (déconseillé)
- com_isenum — Indique si un objet COM a une interface IEnumVariant pour l'itération [Obsolète]
- com_load_typelib — Charge un Typelib
- com_load — Crée une référence sur un composant COM [Obsolète]
- com_message_pump — Traite un message COM dans un délai donné
- com_print_typeinfo — Affiche une définition de classe PHP pour une interface répartissable
- com_propget — Alias de com_get
- com_propput — Alias de com_set
- com_propset — Alias de com_set
- com_release — Décrémente le compteur de références [Obsolète]
- com_set — Modifie une propriété d'un composant COM
- variant_abs — Retourne la valeur absolue d'un variant
- variant_add — "Ajoute" deux valeurs de variants et retourne le résultat
- variant_and — Effectue un ET entre deux variants et retourne le résultat
- variant_cast — Convertit un variant en un nouvel objet variant de type différent
- variant_cat — Assemble deux valeurs variantes ensemble et retourne le résultat
- variant_cmp — Compare deux variants
- variant_date_from_timestamp — Retourne une représentation date en variant d'un timestamp Unix
- variant_date_to_timestamp — Convertit une valeur date/temps variante en un timestamp Unix
- variant_div — Retourne le résultat de la division de deux variants
- variant_eqv — Effectue une équivalence de bits de deux variants
- variant_fix — Récupère la portion entière d'un variant
- variant_get_type — Retourne le type d'un objet variant
- variant_idiv — Convertit des variants en valeurs entières, et effectue alors une division
- variant_imp — Exécute une implication sur les bits de deux variants
- variant_int — Retourne la partie entière d'un variant
- variant_mod — Divise deux variantes et retourne le reste
- variant_mul — Multiplie les valeurs de deux variants
- variant_neg — Effectue une négation logique sur un variant
- variant_not — Exécute une négation sur les bits sur un variant
- variant_or — Performe une disjonction logique sur deux variants
- variant_pow — Retourne le résultat de la fonction puissance avec deux variants
- variant_round — Arrondit le variant au nombre spécifié de décimales
- variant_set_type — Convertit un variant en un autre type "sur-place"
- variant_set — Assigne une nouvelle valeur pour un objet variant
- variant_sub — Soustrait la valeur du variant de droite de la valeur de celui de gauche
- variant_xor — Exécute une exclusion logique sur deux variants
COM
Anonymous
23-Sep-2009 02:00
23-Sep-2009 02:00
Dave Bachtel
27-May-2009 11:20
27-May-2009 11:20
Hello everybody!
Here is some helpful advice for people attempting to use COM with Microsoft MapPoint 2006 or 2009 with PHP.
If you are using apache, it MUST be running under the same credentials as a desktop user that has already installed/run mappoint or modifiy the service and select the "Allow Service to Interact with Desktop" option. Otherwise, it won't work due to the EULA popup having to be accepted. Mappoint 2004 works just fine, this only applies to 2006 and 2009.
For troubleshooting, the error that appears in the System event viewer is:
The server {31851F82-AFE6-11D2-A3C9-00C04F72F340} did not register with DCOM within the required timeout.
The error generated by PHP, if you happen to get lucky and let the COM() function timeout by cranking up set_time_limit() timeout is:
<?php
set_time_limit(1000) ;
$mapoint = new COM("MapPoint.Application") or die("Unable to instantiate Mappoint COM object");
?>
Generates:
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `MapPoint.Application': Server execution failed ' in [somefile.php]:9 Stack trace: #0 [somefile.php](9): com->com('MapPoint.Applic...') #1 {main} thrown in [somefile.php] on line 9
Also, if you have multiple versions of MapPoint installed, you will need to run:
c:\path\to\mappoint\MapPoint.exe /registerserver
(using the correct folder path) to select the right version of the com object to use. Gooood luck!
acsandeep at gmail dot com
05-Apr-2009 07:40
05-Apr-2009 07:40
If you are trying to get the properties of a Word document opened via COM object, you may need to define some constants in your script like so.
<?php
define('wdPropertyTitle', 1);
define('wdPropertySubject', 2);
define('wdPropertyAuthor', 3);
define('wdPropertyKeywords', 4);
define('wdPropertyComments', 5);
define('wdPropertyTemplate', 6);
define('wdPropertyLastAuthor', 7);
$word = new COM("word.application") or die ("Could not initialise MS Word object.");
$word->Documents->Open(realpath("Sample.doc"));
$Author = $word->ActiveDocument->BuiltInDocumentProperties(wdPropertyAuthor);
echo $Author;
?>
long2hu3 ATT yahoo DOTT com
18-Mar-2009 01:38
18-Mar-2009 01:38
When you work with MS Excel, Word, ... and other applications, never forget that COM doesn’t know their predefined constants, thus if you want to do sth. that would look like this in VB:
With myRange.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
you should either use numbers or define constants above, like this:
<?php
define('xlEdgeBottom', 9);
define('xlContinuous', 1);
define('xlThin', 2);
define('xlAutomatic', -4105);
$ex = new COM("Excel.Application", NULL, CP_UTF8) or Die ("Did not instantiate Excel");
$wb = $ex->Application->Workbooks->Add();
$ws = $wb->Worksheets(1);
$xra = $ws->Range("A1:A6");
$bs = $xra->Borders(xlEdgeBottom);
$bs->LineStyle = xlContinuous;
$bs->Weight = xlThin;
$bs->ColorIndex = xlAutomatic;
?>
It is pointless to try to use text strings, i.e.
<?php
$bs = $xra->Borders('xlEdgeBottom');
$bs->Weight = 'xlThin';
?>
this will cause an error: Unable to set property Weight of class Border ...
ilayansmano at gmail dot com
26-Aug-2008 10:39
26-Aug-2008 10:39
Extracting text from Word Documents via PHP and COM
<?php
$word = new COM("word.application") or die ("Could not initialise MS Word object.");
$word->Documents->Open(realpath("Sample.doc"));
// Extract content.
$content = (string) $word->ActiveDocument->Content;
echo $content;
$word->ActiveDocument->Close(false);
$word->Quit();
$word = null;
unset($word);
?>
