代码是这样的:
$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> 因为没有打开的文档,所以这一命令无效。
怎么解决??
$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> 因为没有打开的文档,所以这一命令无效。
怎么解决??
检查显示的文件是否存在
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;
}