CSS 2.1 兼容 HTML 到 Microsoft Word 的转换?

发布于 2024-07-12 11:40:06 字数 170 浏览 9 评论 0原文

我在 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

猫性小仙女 2024-07-19 11:40:07

这里是 pdf => 的一种替代方案 文档。 没试过,祝你好运!

Here is one alternative for pdf => doc. Haven't tried it, good luck!

放飞的风筝 2024-07-19 11:40:07

几年前我不得不这样做,最终推出了我自己的定制解决方案。 我以所需的格式创建了一个 Word 文档,另存为 HTML,然后在需要时添加代码以从数据库检索文本并按照 MS Word 喜欢的方式设置格式。 我强制添加一个标头,让客户端认为它正在接收 Word 文档而不是 HTML 文件。 Microsoft Word 愉快地打开该文件,就像打开普通的 Word 文档一样。

如果可以输出 DOCX 文件,则可以进行 XSL 转换。

I had to do this a few years ago and ended up rolling my own custom solution. I created a Word document in the format I wanted, saved as HTML, and then added code where required to retrieve text from the database and format the way MS Word likes it. I forced a header to make the client think it was receiving a Word Document instead of an HTML file. Microsoft Word happily opened the file as if it were a regular Word Document.

If it were feasible to output a DOCX file instead, you could do an XSL tranform.

云朵有点甜 2024-07-19 11:40:06

三个选项取决于您需要执行的操作:

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

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

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

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

有关此问题的更多信息也可以在这个SO问题中找到。

Three options depending on what you need to do:

  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.

  2. 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.

  3. 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.

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

伪装你 2024-07-19 11:40:06

OpenOffice 可以在服务器/无头模式下使用来生成多种格式的文档。

OpenOffice can be used in server/headless mode to produce documents in lots of formats.

静若繁花 2024-07-19 11:40:06

寻找 PDF 可能会更容易 -> 如果您已经解决了一半的问题,请改为使用 DOC 转换器。 也就是说,我不知道有什么好的 PDF -> DOC 转换器:(

It might be easier to look for a PDF -> DOC converter instead, if you already have one-half of the problem solved. That said, I don't know of any good PDF -> DOC converters either :(

花心好男孩 2024-07-19 11:40:06

You might want to try sending the HTML file as DOC (similar to how it's described link text, but with the proper Contet-Type header :-)) and let the end-user's system do the conversion (AFAIK you can do something similar with Excel too).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文