2016-04-27 83 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