此 HTML Word 文档在 OpenOffice.org 中显示不正确
我在 php 中有这个简单的代码:
<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=kid_tag.doc");
echo '<table cellspacing="0" cellpadding="0" border="0" width="8.4cm">
<tr>
<td colspan="3" style="text-align: right; height: 0.6cm">Nursery</td>
</tr>
<tr>
<td style="height: 1.8cm"><img src="http://images.funadvice.com/photo/image/old/6943/tiny/cat.jpg" /></td>
<td style="text-align: center; font-weight: bold">Sofia Abello</td>
<td> </td>
</tr>
<tr>
<td style="text-align: left; height: 0.6cm">9AM Oct-12-08</td>
<td> </td>
<td style="text-align: right">Dance Studio</td>
</tr>
</table>';
?>
在 MS Office Word 中显示正常,但是,当用 open office writer 打开时,宽度会减小(不是正确的宽度!)。
I have this simple code in php:
<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=kid_tag.doc");
echo '<table cellspacing="0" cellpadding="0" border="0" width="8.4cm">
<tr>
<td colspan="3" style="text-align: right; height: 0.6cm">Nursery</td>
</tr>
<tr>
<td style="height: 1.8cm"><img src="http://images.funadvice.com/photo/image/old/6943/tiny/cat.jpg" /></td>
<td style="text-align: center; font-weight: bold">Sofia Abello</td>
<td> </td>
</tr>
<tr>
<td style="text-align: left; height: 0.6cm">9AM Oct-12-08</td>
<td> </td>
<td style="text-align: right">Dance Studio</td>
</tr>
</table>';
?>
displays ok with MS Office Word, however, width is reduced (not proper width!) when opened with open office writer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为使用 PHP 生成 DOC 文件的最简单方法是使用 Zend Framework 组件 phpLiveDocx。 您可以加载 Word 或 Open Office 模板、合并文本数据并将最终文档保存为多种格式,例如 DOC、DOCX、RTF 和 PDF。
在项目网站上了解更多信息:
http://www.phplivedocx.org /articles/phplivedocx 简介/
I think the easiest way to generate DOC files with PHP is using the Zend Framework component phpLiveDocx. You can load Word or Open Office templates, merge textual data and save the final document to a number of formats, such as DOC, DOCX, RTF and PDF.
Learn more on the project web site:
http://www.phplivedocx.org/articles/brief-introduction-to-phplivedocx/
您实际上是将 HTML 导入到 MS Word 和 OpenOffice.org 中。 HTML 不是 Word 和 OpenOffice.org 的本机格式,这意味着必须首先转换输入。
毫不奇怪,这些应用程序(其主要目的是以应用程序的本机格式编辑文档)在那里做得并不完美。 事实上 - 这不是什么大秘密 - 即使是主要目的是渲染 HTML 的网络浏览器在该领域也并不完美。
解决方案是提供适用于这两种应用程序的 HTML。 您可以使用条件注释来做到这一点,这是 Microsoft 对 HTML 的专有扩展,因此只能由微软产品。
这就是您的示例中的样子:
You are actually importing HTML into MS Word and OpenOffice.org. HTML is not the native format of neither Word nor OpenOffice.org, which means the input has to be converted first.
It is no surprise that these applications (whose main purpose is the editing of documents in the application's native format) are doing not a perfect job there. In fact - and that's not a big secret - not even web browsers, whose main purpose is the rendering of HTML are not perfect in that area.
The solution would be to provide HTML which works in both applications. You could do that using conditional comments which are a proprietary Microsoft extension to HTML and therefore only understood by Microsoft products.
This is how it could look like in your example: