CSS 2.1 兼容 HTML 到 Microsoft Word 的转换? [英] CSS 2.1 compliant HTML to Microsoft Word conversion?

查看:33
本文介绍了CSS 2.1 兼容 HTML 到 Microsoft Word 的转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Prince XML 中找到了一个极好的 HTML 到 PDF 转换器.现在我正在寻找类似质量的东西来从 HTML + CSS 生成 Word 文档.这是在 PHP/Linux 上.

I've found a superb HTML to PDF converter in Prince XML. Now I'm looking for something of similar quality to produce Word documents from HTML + CSS. This is on PHP/Linux.

推荐答案

三个选项取决于您需要做什么:

Three options depending on what you need to do:

  1. 对于简单的情况,您只需将 HTML 写入 .doc 文件即可.示例 此处.但是,这是有限的,并且会在用户进行更新时提示用户另存为 HTML.

  1. For simple cases, you can just write out the HTML to a .doc file. Sample here. That's limited, though, and prompts the user to save as HTML if they make updates.

如果您需要 Word 2007,则可以生成 Office Open XML,它基本上是一个包含 XML 文档的 zip 文件.我还没有找到可以做到这一点的库,但是您可以通过将示例 .docx 文件重命名为 .zip 文件并查看包含的内容,然后从 PHP 生成它来开始.this SO question中的一些信息.

If you can require Word 2007, you can generate Office Open XML, which is basically a zip file which holds XML documents. I haven't found a library that can do that, but you can get started by renaming a sample .docx file to a .zip file and looking at what's included, then generate that from PHP. Some info on that in this SO question.

如果您需要支持 Word 2003,则需要使用 Word 2003 的 XML 格式.它与 2007 格式不同,但至少向前兼容(因此它也适用于 2007).最简单的方法是从 Word 中另存为 Word 2003 XML 文档,然后在文本编辑器中打开该文档,然后开始编写 XSLT,将您的 HTML 转换为正确的 XML.我已经做到了,并且奏效了,但工作量很大.有关于格式的信息这里.

If you need to support Word 2003, you need to work with Word 2003's XML format. It's different than the 2007 format, but is at least forward compatible (so it'll work on 2007 as well). The simplest way is to save as a Word 2003 XML document from Word, then open the document in a text editor, then get to work writing XSLT that will convert your HTML to the correct XML. I've done it, and it worked, but it was a lot of work. There's info on the format here.

这些都不是那么容易,因此可能值得购买为您进行转换的软件产品.

None of those are all that easy, so it might be worth buying a software product that does the conversion for you.

this SO question中提供了有关此问题的更多信息,也一样.

More info on this question is available in this SO question, as well.

这篇关于CSS 2.1 兼容 HTML 到 Microsoft Word 的转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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