我的PHP是4.2.3,需要什么版本?

解决方案 »

  1.   

    modify php.ini
    [com]
    com.allow_dcom = true;
      

  2.   

    注意文件存放路径的写法
    <?php
    $word = new COM("word.application") or die("不能实例化Word");
    $word->Visible = 1;
    $word->Documents->Add();
    $word->Selection->TypeText("This is a test...\n Can u see this?");
    $word->Documents[1]->SaveAs("c:/test.doc");//notice here,the path of file
    $word->Quit();
    ?>
      

  3.   

    运行COM,第一次是很慢;再运行就很快!
    要在文件头设一下超时set_time_limit(300);
    等吧!!
    试出好办法一定发布......
      

  4.   

    <?php
    $word = new COM("word.application") or die("不能实例化Word");
    $word->Visible = 1;
    $word->Documents->Add();
    $word->Selection->TypeText("This is a test...\n Can u see this?");
    $word->Documents[1]->SaveAs("c:/test.doc");//notice here,the path of file
    $word->Quit();
    ?>
    用这段代码试也没结果吗?
      

  5.   

    看看c盘根目录下是否有test.doc这个文件,如果有就说明成功了。
      

  6.   

    没有,我怀疑是我的php.ini配置错误,可是错误他也没给我出什么提示啊。
    谢谢uGain(幽亙)兄的热情解答!
      

  7.   

    会不会是缺什么组件?我去php.net看了,也没什么特别的啊。只是说只能在windows上用COM。如果不行就用别的办法。
      

  8.   

    也有可能是网页执行超时了,所以没有返回结果。
    把php.ini中
    max_execution_time 改大些。
      

  9.   

    我也需要这个功能,而且试过多次,没有成功,有个家伙说他拿我的代码运行成了,不过我不信.
    PHP版上,这个问题好象从来就没解决过.
    谁要是真正的大虾,就出来露两手!!!
      

  10.   

    的确可以执行,结果在指定目录生成了.doc文件。
    似乎关键是在最后文件保存的写法。
    试了几种方法,只有这样写才有结果。
    大家也可以试试。
    <?php
    $word = new COM("word.application") or die("不能实例化Word");
    $word->Visible = 1;
    $word->Documents->Add();
    $word->Selection->TypeText("This is a test...\n Can u see this?");
    $word->Documents[1]->SaveAs("c:/test.doc");//notice here,the path of file
    $word->Quit();
    ?>
      

  11.   

    测试过了没有问题,可以生成一个test.doc文件。我用的是php4.2.3,win2000 server ,apache 在php.ini中去掉[com]中com.allow_dcom = true前的引号,重起机器运行wordtest.php文件(内容是 uGain(幽亙) 老兄的):
    <?php
    $word = new COM("word.application") or die("不能实例化Word");
    $word->Visible = 1;
    $word->Documents->Add();
    $word->Selection->TypeText("This is a test...\n Can u see this?");
    $word->Documents[1]->SaveAs("c:/test.doc");//notice here,the path of file
    $word->Quit();
    ?>过了5-6秒后,在C:生成了一个test.doc文件。
      

  12.   

    文件保存时,要注意写成 c:\\test.doc or c:/test.doc 。
      

  13.   

    我把那段代码拷过来运行,还是老问题。甚至我用最简化的
    $word = new COM("word.application") or die("不能实例化Word");
    都不行。
      

  14.   

    把你httpd.conf和php.ini都最简化试试,不要加载暂时不用的模块。
      

  15.   

    WIN下的PHP有时候要靠运气的,完全相同的配置有的行,有的却不行,用COM操作WORD本人以前也试过,用4.2.3的怎么也不行,后来改成php4.3.0或4.1.2不用改任何配置就行了。这很正常。