在没有安装 MS Word 的情况下将 html 导出到 Word 的最佳方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:09:37  来源:igfitidea点击:

Best way to export html to Word without having MS Word installed?

htmlms-word

提问by Robert Dean

Is there a way to export a simple HTML page to Word (.doc format, not .docx) without having Microsoft Word installed?

有没有办法在没有安装 Microsoft Word 的情况下将简单的 HTML 页面导出到 Word(.doc 格式,而不是 .docx)?

采纳答案by Biri

If you have only simple HTML pages as you said, it can be opened with Word.

如果你说的只有简单的HTML页面,可以用Word打开。

Otherwise, there are some libraries which can do this, but I don't have experience with them.

否则,有一些库可以做到这一点,但我没有使用它们的经验。

My last idea is that if you are using ASP.NET, try to add application/mswordto the header and you can save it as a Word document (it won't be a real Word doc, only an HTML renamed to docto be able to open).

我的最后一个想法是,如果您使用的是 ASP.NET,请尝试添加application/msword到标题中,然后您可以将其另存为 Word 文档(它不会是真正的 Word 文档,只有重命名为doc能够打开的 HTML ) .

回答by Andrew Hancox

There's a tool called JODConverter which hooks into open office to expose it's file format converters, there's versions available as a webapp (sits in tomcat) which you post to and a command line tool. I've been firing html at it and converting to .doc and pdf succesfully it's in a fairly big project, haven't gone live yet but I think I'm going to be using it. http://sourceforge.net/projects/jodconverter/

有一个名为 JODConverter 的工具,它连接到开放式办公室以公开它的文件格式转换器,有一些版本可用作您发布到的 web 应用程序(位于 tomcat 中)和一个命令行工具。我一直在使用 html 并成功地转换为 .doc 和 pdf 它在一个相当大的项目中,还没有上线,但我想我会使用它。 http://sourceforge.net/projects/jodconverter/

回答by James Stallings

There is an open source project called HTMLtoWordthat that allows users to insert fragments of well-formed HTML (XHTML) into a Word document as formatted text.

有一个名为HTMLtoWord 的开源项目,它允许用户将格式良好的 HTML (XHTML) 片段作为格式化文本插入到 Word 文档中。

HTMLtoWord documentation

HTMLtoWord 文档

回答by JasonPlutext

If you are working in Java, you can convert HTML to real docx content with code I released in docx4j 2.8.0. I say "real", because the alternative is to create an HTML altChunk, which relies on Word to do the actual conversion (when the document is first opened).

如果您使用 Java,则可以使用我在docx4j 2.8.0 中发布的代码将 HTML 转换为真正的 docx 内容。我说“真实”,因为另一种方法是创建一个 HTML altChunk,它依赖于 Word 进行实际转换(当第一次打开文档时)。

See the various samples prefixed ConvertInXHTML. The import process expects well formed XML, so you might have to tidy it first.

请参阅以 ConvertInXHTML 为前缀的各种示例。导入过程需要格式良好的 XML,因此您可能必须先对其进行整理。

回答by Neall

While it is possible to make a ".doc" Microsoft Word file, it would probably be easier and more portable to make a ".rtf" file.

虽然可以制作“.doc”Microsoft Word 文件,但制作“.rtf”文件可能更容易和更便携。

回答by Joel Coehoorn

If it's just HTML, all you need to do is change the extension to .doc and word will open it as if it's a word document. However, if there are images to include or javascript to run it can get a little more complicated.

如果它只是 HTML,您需要做的就是将扩展名更改为 .doc,word 会像打开 word 文档一样打开它。但是,如果要包含图像或要运行 javascript,则可能会变得更复杂一些。

回答by Peter Evjan

Well, there are many third party tools for this. I don't know if it gets any simpler than that.

嗯,有很多第三方工具可以做到这一点。我不知道它是否比这更简单。

Examples:

例子:

Also found a vbscribt, but I'm guessing that requires that you have word installed.

还找到了一个vbscribt,但我猜这需要你安装 word。

回答by Ian Nelson

I presume from the "C#" tag you wish to achieve this programmatically.

我从“C#”标签中推测您希望以编程方式实现这一目标。

Try Aspose.Words for .NET.

试试Aspose.Words for .NET

回答by JimmyJ

i believe open officecan both open .html files and create .doc files

我相信开放式办公室既可以打开 .html 文件,也可以创建 .doc 文件

回答by user4757345

You can open html files with LibreofficeWriter. Then you can export as PDF from File menu. Also browsers can export html as a PDF file.

您可以使用LibreofficeWriter打开 html 文件。然后您可以从文件菜单导出为 PDF。浏览器也可以将 html 导出为 PDF 文件。