用PHP生成的Word文档的显示模式 [英] Display mode of Word document generated in PHP

查看:103
本文介绍了用PHP生成的Word文档的显示模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将页面导出到.doc文件,但是当我打开生成的.doc时,它将在weblayout-view(而不是print-view)中打开.这是丑陋且令人困惑的.有没有一种方法可以将其设置为打印视图?

I want to export a page to a .doc file but when I open the generated .doc it opens in weblayout-view instead of print-view. This is ugly and confusing. Is there a way to set it to print-view?

我用来生成文档的脚本:

The script I use to generate the 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>

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

And now that i'm here is it possible to add word-checkboxes ☒ and word-input fields?

推荐答案

这对我有用:

<?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>

这篇关于用PHP生成的Word文档的显示模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆