我运行脚本后出现 Uncaught,我的脚本出现问题 例外' com_exception'有消息'来源:Microsoft Word说明:命令失败'
并显示提醒: http://imgur.com/HrDYrah
这是我的代码:
<?php
$word = new COM("Word.Application") or die ("Could not initialise Object.");
// set it to 1 to see the MS Word window (the actual opening of the document)
$word->Visible = 0;
// recommend to set to 0, disables alerts like "Do you want MS Word to be the default .. etc"
$word->DisplayAlerts = 0;
// open the word 2007-2013 document
$word->Documents->Open('C:\xampp\htdocs\Open_Office\test_4sk.docx');
// save it as word 2003
$word->ActiveDocument->SaveAs('C:\xampp\htdocs\Open_Office\newdocument.doc');
// convert word 2007-2013 to PDF
$word->ActiveDocument->ExportAsFixedFormat("C:\\xampp\htdocs\Open_Office\Main_PDF.pdf", 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);
// quit the Word process
$word->Quit(false);
// clean up
unset($word);
?>
答案 0 :(得分:1)
将您的代码更改为:
<?php
try{
$word = new COM("Word.Application") or die ("Could not initialise Object.");
// set it to 1 to see the MS Word window (the actual opening of the document)
$word->Visible = 0;
// recommend to set to 0, disables alerts like "Do you want MS Word to be the default .. etc"
$word->DisplayAlerts = 0;
// open the word 2007-2013 document
$word->Documents->Open('C:\xampp\htdocs\Open_Office\test_4sk.docx');
// save it as word 2003
$word->ActiveDocument->SaveAs('C:\xampp\htdocs\Open_Office\newdocument.doc');
// convert word 2007-2013 to PDF
$word->ActiveDocument->ExportAsFixedFormat("C:\\xampp\htdocs\Open_Office\Main_PDF.pdf", 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);
// quit the Word process
$word->Quit(false);
// clean up
unset($word);
}catch(Exception $e){
echo $e;
}
?>
这样它就不会停止代码的执行,你可以看到它以防它发生。请注意,这里理想的做法是将echo $e;
替换为实际的错误处理。