- 在PHP代码里利用html拼接想要的文档样式。
$html= '<!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <title>课表</title> </head> <body></body></html>';
在<body></body>实现你要的样式
- 直接输出到浏览器。
echo $html; ob_start(); //打开缓冲区 header("Cache-Control: public"); Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); $filename = rawurlencode("放假通知"); header('Content-Disposition: attachment; filename='.$filename.'.doc'); header("Pragma:no-cache"); header("Expires:0"); ob_end_flush();//输出全部内容到浏览器
只要以上代码,即可实现在浏览器输出word文档。