注意文件存放路径的写法 <?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(); ?>
<?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(); ?> 用这段代码试也没结果吗?
的确可以执行,结果在指定目录生成了.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(); ?>
测试过了没有问题,可以生成一个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文件。
文件保存时,要注意写成 c:\\test.doc or c:/test.doc 。
我把那段代码拷过来运行,还是老问题。甚至我用最简化的 $word = new COM("word.application") or die("不能实例化Word"); 都不行。
[com]
com.allow_dcom = true;
<?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();
?>
要在文件头设一下超时set_time_limit(300);
等吧!!
试出好办法一定发布......
$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();
?>
用这段代码试也没结果吗?
谢谢uGain(幽亙)兄的热情解答!
把php.ini中
max_execution_time 改大些。
PHP版上,这个问题好象从来就没解决过.
谁要是真正的大虾,就出来露两手!!!
似乎关键是在最后文件保存的写法。
试了几种方法,只有这样写才有结果。
大家也可以试试。
<?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();
?>
<?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文件。
$word = new COM("word.application") or die("不能实例化Word");
都不行。