Unusual behaviour opening Word document

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Csaba Gabor

    Unusual behaviour opening Word document

    If I do not have the indicated Word document open (on my Win XP Pro
    machine with PHP 5.2), the following will open and display it:

    <?php
    $path = "c:\\path\\to\\ word\\document\ \mydoc.doc";
    $doc = new COM($path);
    $doc->Application->visible = true;
    ?>

    However, there will be several identical warnings (14 in number)
    associated with line 3 (the new COM line):

    Warning: com::com(): Type library constant emptyenum is already defined
    in C:\test.php on line 3

    Am I getting lucky that the doc is opened at all (and hence the
    warnings are not bugs), or should this behaviour be reported? This
    type of functionality works fine in vbscript:

    Path = "c:\path\to\wor d\document\mydo c.doc"
    Set doc = CreateObject(Pa th)
    doc.Application .visible = true

    Thanks,
    Csaba Gabor from Vienna

    PS. Note that if the doc is already opened, the above scripts fail.

  • Csaba Gabor

    #2
    Re: Unusual behaviour opening Word document

    Csaba Gabor wrote:
    If I do not have the indicated Word document open (on my Win XP Pro
    machine with PHP 5.2), the following will open and display it:
    >
    <?php
    $path = "c:\\path\\to\\ word\\document\ \mydoc.doc";
    $doc = new COM($path);
    $doc->Application->visible = true;
    ?>
    >
    However, there will be several identical warnings (14 in number)
    associated with line 3 (the new COM line):
    >
    Warning: com::com(): Type library constant emptyenum is already defined
    in C:\test.php on line 3
    >
    Am I getting lucky that the doc is opened at all (and hence the
    warnings are not bugs), or should this behaviour be reported? This
    type of functionality works fine in vbscript:
    >
    Path = "c:\path\to\wor d\document\mydo c.doc"
    Set doc = CreateObject(Pa th)
    doc.Application .visible = true
    >
    Thanks,
    Csaba Gabor from Vienna
    >
    PS. Note that if the doc is already opened, the above scripts fail.
    OK, this doesn't have anything to do with the specific document. It
    also happens if you just do:
    $word = new COM("Word.Appli cation");


    Initial indications are that the following will suppress the warnings:

    $c_artext = "com.autoregist er_typelib";
    if ($c_ar_t=ini_ge t($c_artext)) ini_set($c_arte xt,0);
    ....
    $word = new COM("Word.Appli cation");
    ....
    if ($c_ar_t) ini_set($c_arte xt, $c_ar_t);

    Comment

    • Alvaro G. Vicario

      #3
      Re: Unusual behaviour opening Word document

      *** Csaba Gabor escribió/wrote (24 Jul 2006 05:27:59 -0700):
      <?php
      $path = "c:\\path\\to\\ word\\document\ \mydoc.doc";
      $doc = new COM($path);
      $doc->Application->visible = true;
      ?>
      According to PHP manual, COM constructor doesn't expect a file name:

      com COM::COM ( string module_name [, mixed server_name [, int codepage [,
      string typelib]]] )

      module_name
      Can be a ProgID, Class ID or Moniker that names the component to load.

      A ProgID is typically the application or DLL name, followed by a period,
      followed by the object name. e.g: Word.Applicatio n.

      A Class ID is the UUID that uniquely identifies a given class.

      A Moniker is a special form of naming, similar in concept to a URL scheme,
      that identifies a resource and specifies how it should be loaded. As an
      example, you could load up Word and get an object representing a word
      document by specifying the full path to the word document as the module
      name, or you can use LDAP: as a moniker to use the ADSI interface to LDAP.



      In my computer, the code just crashes PHP interpreter.


      --
      -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
      ++ Mi sitio sobre programación web: http://bits.demogracia.com
      +- Mi web de humor con rayos UVA: http://www.demogracia.com
      --

      Comment

      • Csaba Gabor

        #4
        Re: Unusual behaviour opening Word document

        Alvaro G. Vicario wrote:
        *** Csaba Gabor escribió/wrote (24 Jul 2006 05:27:59 -0700):
        <?php
        $path = "c:\\path\\to\\ word\\document\ \mydoc.doc";
        $doc = new COM($path);
        $doc->Application->visible = true;
        ?>
        >
        According to PHP manual, COM constructor doesn't expect a file name:
        That's why I posted. It wasn't entirely clear to me whether my
        construct was legal under PHP. But, if you read my subsequent post,
        you saw that that was not what the errors were due to.
        ....
        In my computer, the code just crashes PHP interpreter.
        The code I gave was for PHP 5.2 on Win XP Pro (and Word 2003).
        The calls with COM code are significantly different for PHP 5 vs. PHP
        4.

        What machine/PHP/Word are you using?
        Csaba

        Comment

        Working...