发新话题
打印

PHP直接将html导出doc文件并使其doc横向排版

PHP直接将html导出doc文件并使其doc横向排版

注意要在html中添加个Section2的类标签 class=Section2 付给最大的div
下面是整个PHP代码
<?php
export_temporary();
function export_temporary(){
echo '<html xmlns:office="urn:schemas-microsoft-com:office:office"
xmlns:word="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<style>        
@page Section1 {size:595.45pt 841.7pt; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}
        div.Section1 {page:Section1;}
        @page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}
        div.Section2 {page:Section2;}
</style>
</head>';
$data  = '<body>';
$data .= '<div class=Section2>这个是横版的,要设置宽度</div>';//这里是主要内容
$data .='</body></html>';
echo $data;
ob_start(); //打开缓冲区
header("Cache-Control: public");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
if (strpos($_SERVER["HTTP_USER_AGENT"],'MSIE')) {
    header('Content-Disposition: attachment; filename=预约申请.doc');
}else if (strpos($_SERVER["HTTP_USER_AGENT"],'Firefox')) {
    Header('Content-Disposition: attachment; filename=预约申请.doc');
} else {
    header('Content-Disposition: attachment; filename=预约申请.doc');
}
header("Pragma:no-cache");
header("Expires:0");
ob_end_flush();//输出全部内容到浏览器
}

TOP

发新话题