0

您好我正在使用 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;?>

帮帮我,我很失望。提前致谢。

4

1 回答 1

1

我不确定您是否已经有想要使用您的应用程序发送的 Word 文档,或者您是否想要动态创建Word 文档...

如果是第二种选择,您可能想看看 PHPOffice/PHPWord,它是 PHP 中用于读取和写入 Word 文档的库。

它有很好的记录,可能会解决您的问题:

https://github.com/PHPOffice/PHPWord

希望这可以帮助,

更新

再多说几句(不是双关语......)......

PHPWord 在https://github.com/PHPOffice/PHPWord/tree/develop/samples中有大量示例

我很确定其中一个或混合会解决您的需求。

希望这可以帮助,

于 2016-04-28T01:00:45.430 回答