简体   繁体   English

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

[英]Best way to export html to Word without having MS Word installed?

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

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/msword to the header and you can save it as a Word document (it won't be a real Word doc, only an HTML renamed to doc to be able to open).我的最后一个想法是,如果您使用的是 ASP.NET,请尝试将application/msword添加到标题中,然后您可以将其另存为 Word 文档(它不会是真正的 Word 文档,只有重命名为doc的 HTML可以打开)。

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

There is an open source project called HTMLtoWord that 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 文档

If you are working in Java, you can convert HTML to real docx content with code I released in docx4j 2.8.0 .如果您使用 Java,则可以使用我在docx4j 2.8.0 中发布的代码将 HTML 转换为真正的 docx 内容。 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).我说“真实”,因为另一种方法是创建一个 HTML altChunk ,它依赖于 Word 进行实际转换(当第一次打开文档时)。

See the various samples prefixed ConvertInXHTML .请参阅以 ConvertInXHTML 为前缀的各种示例 The import process expects well formed XML, so you might have to tidy it first.导入过程需要格式良好的 XML,因此您可能必须先对其进行整理。

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

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。

I presume from the "C#" tag you wish to achieve this programmatically.我从“C#”标签中推测您希望以编程方式实现这一目标。

Try Aspose.Words for .NET .试试Aspose.Words for .NET

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.如果它只是 HTML,您需要做的就是将扩展名更改为 .doc,word 会像打开 word 文档一样打开它。 However, if there are images to include or javascript to run it can get a little more complicated.但是,如果要包含图像或要运行 javascript,则可能会变得更复杂一些。

You can open html files with Libreoffice Writer.您可以使用Libreoffice Writer 打开 html 文件。 Then you can export as PDF from File menu.然后您可以从文件菜单导出为 PDF。 Also browsers can export html as a PDF file.浏览器也可以将 html 导出为 PDF 文件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM