2012-07-10 55 views
0

我試圖根據PHPWord example的示例示例生成一個單詞模板。但是沒有生成單詞模板或者無法成功顯示頁面。我已經過濾了示例代碼,只添加了hello world的一個部分!配置和運行PHPWord

Code: 
<?php 
    require_once 'PHPWord.php'; 
    $PHPWord = new PHPWord(); 
    $section = $PHPWord->createSection(); 
    $section->addText('Hello world!'); 
    header("Cache-Control: public"); 
    header("Content-Description: File Transfer"); 
    header("Content-Disposition: attachment; filename=helloWorld.docx"); 
    header("Content-Type: application/docx"); 
    header("Content-Transfer-Encoding: binary"); 
    $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); 
    $objWriter->save('helloWorld.docx'); 
    ?> 

請注意,如果我使用objwriter->保存helloworld.docx。它會自動進入我的網絡服務器嗎?或臨時文件夾?

謝謝!

+0

文件將在你的腳本運行 – 2012-07-10 13:59:15

+0

確定當前工作目錄中創建。任何想法爲什麼我的網頁不能加載?它會顯示一個下載圖標? – JLearner 2012-07-10 14:00:23

+0

不,它不會顯示下載圖標,也沒有任何輸出到代碼中的瀏覽器(除了標題)。這將簡單地執行並將文件寫入服務器的磁盤......標題是毫無意義的。如果要將輸出發送到瀏覽器,請使用「按原樣」標題,但將save()調用中的文件名更改爲php://輸出 – 2012-07-10 14:09:03

回答

0

如果你希望你的網頁來強制下載所生成的文檔,只需使用以下命令:

$PHPWord->save('helloWorld.docx', 'Word2007', true);