word文档生成

/**
* 下载作文内容到doc文件
*/
public function actionSaveCompositionWord()
{
//加载数据模型
$model = $this->loadModel();

header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

$wordStr = '<html xmlns:o="urn:schemas-microsoft-com:office:office" 
           xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
           <head><STYLE>BR.page { page-break-after: always }</STYLE></head><body>';

$wordStr .= $model->content;

$wordStr .= '</body></html>';

$fileName = $model->composition_name . '_' . $model->real_name;

//防止导出乱码
$file = iconv("utf-8", "GBK", $fileName);

header("Content-Type: application/doc");
header("Content-Disposition: attachment; filename=" . $file . ".doc");

echo $wordStr;
}
发布了14 篇原创文章 · 获赞 3 · 访问量 2029

猜你喜欢

转载自blog.csdn.net/energy_tank/article/details/46621161