加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

在PHP中生成的Word文档的显示模式

发布时间:2020-12-13 17:20:09 所属栏目:PHP教程 来源:网络整理
导读:我想将页面导出到.doc文件,但是当我打开生成的.doc时,它会在weblayout-view而不是print-view中打开.这是丑陋和令人困惑的.有没有办法将其设置为打印视图? 我用来生成doc的脚本: ?php if(isset($_GET['word'])) { header("Content-Type: application/vnd.ms
我想将页面导出到.doc文件,但是当我打开生成的.doc时,它会在weblayout-view而不是print-view中打开.这是丑陋和令人困惑的.有没有办法将其设置为打印视图?

我用来生成doc的脚本:

<?php  if(isset($_GET['word'])) {
    header("Content-Type: application/vnd.ms-word");
    header("Expires: 0");
    header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
    header("content-disposition: attachment;filename=test.doc");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
  <title>Example</title>
  <style type="text/css"> /* SOME STYLING */ </style>
</head>
<body>
  <h1>Hello StackOverflow!</h1>
  <p>Lorem ipsum...</p>
</body>
</html>

现在,我在这里是否可以添加单词复选框?和单词输入字段?

解决方法

这对我有用:

<?php
header("Cache-Control: ");// leave blank to avoid IE errors
header("Pragma: ");// leave blank to avoid IE errors
header("Content-type: application/octet-stream");
header("content-disposition: attachment;filename=FILENAME.doc"); 
?>
<html xmlns:v="urn:schemas-microsoft-com:vml"
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>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 9">
<meta name=Originator content="Microsoft Word 9">
<!--[if !mso]>
<style>
v:* {behavior:url(#default#VML);}
o:* {behavior:url(#default#VML);}
w:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>title</title>
<!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:View>Print</w:View>
  <w:DoNotHyphenateCaps/>
  <w:PunctuationKerning/>
  <w:DrawingGridHorizontalSpacing>9.35 pt</w:DrawingGridHorizontalSpacing>
  <w:DrawingGridVerticalSpacing>9.35 pt</w:DrawingGridVerticalSpacing>
 </w:WordDocument>
</xml><![endif]-->
<style>
</head>
<body>
  Yes printview!
</body>
</html>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读