您好我正在使用 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;?>
帮帮我,我很失望。提前致谢。