代码是这样的:
                $word = new COM("word.application") or die ("Could not initialise MS Word object.");
                header("Content-Type:text/html; charset=GBK");
                $word->Documents->Open(realpath($file_dir . $name));
                $content = (string) $word->ActiveDocument->Content;
结果显示:
#Exception: <b>Source:</b> Microsoft Word<br/><b>Description:</b> 因为没有打开的文档,所以这一命令无效。
怎么解决??

解决方案 »

  1.   

    echo realpath($file_dir . $name);
    检查显示的文件是否存在
      

  2.   

    那你就看看是否是 doc 文件
      

  3.   

    我贴完整的代码吧..
    if(!file_exists($file_dir . $name)){
                    echo '文件不存在';
                    return;
                }if(strtolower(substr(strrchr($path, '.'), 1)) == 'doc'){
                    $word = new COM("word.application") or die ("Could not initialise MS Word object.");
                    header("Content-Type:text/html; charset=GBK");
                    $word->Documents->Open(realpath($file_dir . $name));
                    $content = (string) $word->ActiveDocument->Content;
    }