2013-12-16 38 views

回答

0

試試這個根據你這個

$word = new COM("word.application"); 

// Hide MS Word application window 
$word->Visible = 0; 


$template_file = 'C:/xampp/htdocs/portal/includes/templates/form1.docx'; 
//file name is different based on initiating form. 

//Create new document 
$word->Documents->Open($template_file); 
//WO Number 
$woNumBookMark = 'WONum'; 
$objBookmark = $word->ActiveDocument->Bookmarks($woNumBookMark); 
$range = $objBookmark->Range; 
$range->Text = htmlentities($workOrderNum) . '/' . htmlentities($lotID); 
$filename = tempnam(sys_get_temp_dir(), "word"); 
$word->Documents[1]->SaveAs($filename); 

// Close and quit 
$word->Quit(); 
unset($word); 
header("Content-Length: ".filesize($filename)); 
//header("Content-Type: application/force-download"); 
header("Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document"); 
header("Content-Disposition: attachment;Filename=document_name.docx"); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Pragma: public'); 

// Send file to browser 

readfile($filename); 
unlink($filename); 

變化。

希望這個幫助

+0

致命錯誤:無法實例化不存在的類:com – erdemildiz

+0

請參閱http://stackoverflow.com/questions/277224/how-do-i-catch-a-php-fatal-錯誤 –

+0

謝謝你的回答。我在互聯網上做了一些關於COM的研究。 COM需要工作窗口或.net機器。我的machice linux。 – erdemildiz