2016-04-27 87 views
0

嗨我正在使用cakephp將頁面內容導出到MS word文檔。 這件事對我來說是全新的,我以前沒有用過任何語言。 到目前爲止,谷歌搜索後,我無法找到很多關於此。 但是,我發現這樣的藝術。將內容導出到cakephp中的MS Word文檔中

「詞」的佈局:

<?php 
header("Content-Type: application/vnd.ms-word"); 
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past - so must always re-read 
header("content-disposition: attachment;filename=myfile.doc"); //this will be the name of the file the user downloads 
echo $content_for_layout; ?> 

控制器功能:

function printToWord($pageId) { 
    $page = $this->Customer->findById($pageId); 
    $this->set('page',$page); 
    $file = new File(APP.DS.'webroot'.DS.'css'.DS.'print.css', false); //1 
    $this->set('inlineCss',$file->read()); //2 
    $file->close(); 
    $this->layout = "word"; 
    Configure::write('debug',0); 
} 

,並考慮:

<style> 
<?php if (isset($inlineCss) echo $inlineCss;?> 

幫助我,我很失望。 在此先感謝。

回答

0

我不知道你是否已經有了一個Word文檔,您想要使用的應用程序發送,或者如果你想創建動態Word文檔...

如果是第二個選項,你可以想看看PHPOffice/PHPWord,它是PHP中的一個庫,用於讀寫Word文檔。

這是非常有據可查,並可能會解決您的問題:

https://github.com/PHPOffice/PHPWord

希望這有助於

UPDATE

短短几句話(沒有雙關語意.. 。)...

PHPWord有廣泛的範例es在https://github.com/PHPOffice/PHPWord/tree/develop/samples

我很確定其中一個或混合將解決您的需求。

希望這會有所幫助,

+0

第二個選項..我想動態創建word文檔嗎? 你能幫助我嗎? @Pbal –

+0

這個庫支持MS詞嗎? –

+0

@MuhammadUsman:是的!有了這個庫,你可以動態地生成Word文檔。查看「入門」部分。這是非常直接的使用。 – Pbal