如何将 HTML 文件转换为 Word?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1624485/
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
How to convert HTML file to word?
提问by Mask
I need to save HTML documents in memory as Word .DOC files.
我需要将 HTML 文档作为 Word .DOC 文件保存在内存中。
Can anybody give me some links to both closed and open source libraries that I can use to do this?
任何人都可以给我一些封闭和开源库的链接,我可以用它来做这件事吗?
Also, I should edit this question to add the language I'm using in order to narrow down the choices.
此外,我应该编辑此问题以添加我正在使用的语言以缩小选择范围。
回答by Jan
Try using pandoc
尝试使用 pandoc
pandoc -f html -t docx -o output.docx input.html
If the input or output format is not specified explicitly, pandoc will attempt to guess it from the extensions of the input and output filenames.
— pandoc manual
如果未明确指定输入或输出格式,pandoc 将尝试从输入和输出文件名的扩展名中猜测它。
— pandoc 手册
So you can even use
所以你甚至可以使用
pandoc -o output.docx input.html
回答by SAR
just past this on head of your php page. before any code on this should be the top code.
刚刚在你的 php 页面的头部过去。在此之前的任何代码都应该是最上面的代码。
<?php
header("Content-Type: application/vnd.ms-word");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=Hawala.doc");
?>
this will convert all html to MSWORD, now you can customize it according to your client requirement.
这会将所有 html 转换为 MSWORD,现在您可以根据您的客户要求对其进行自定义。
回答by user1980965
回答by SnapShot
When doing this I found it easiest to:
这样做时,我发现最容易:
- Visit the page in a web browser
- Save the page using the web browser with .htm extension (and maybe a folder with support files)
- Start Word and open the saved htmfile (Word will open it correctly)
- Make any edits if needed
- Select Save As and then choose the extension you would like doc, docx, etc.
- 在网络浏览器中访问页面
- 使用带有 .htm 扩展名的 Web 浏览器保存页面(可能还有一个包含支持文件的文件夹)
- 启动Word并打开保存的htmfile(Word会正确打开)
- 如果需要,进行任何编辑
- 选择另存为,然后选择您想要的扩展名 doc、docx 等。
回答by sleath
Other Alternatives from just renaming the file to .doc.....
其他替代方法只是将文件重命名为 .doc .....
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word(office.11).aspx
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word(office.11).aspx
Here is a good place to start. You can also try using this Office Open XML.
这是一个很好的起点。您也可以尝试使用此 Office Open XML。
http://www.ecma-international.org/publications/standards/Ecma-376.htm
http://www.ecma-international.org/publications/standards/Ecma-376.htm