从 HTML 导出到 MS Word
如何使用 VB.NET 在 ASP.NET 中将 HTML 保存为 Microsoft Word 文档?我需要一个特殊的库来执行转换吗?
How I can save HTML as Microsoft Word Document in ASP.NET with VB.NET? Do I need a special library to perform the conversion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
考虑到 MS Word 可以立即读取 HTML,您只需将 Response.ContentType 更改为 application/ms-word 即可。
但是,如果您想要创建
.doc
文件,您可能需要查看 办公自动化。另一种方法是创建 XML MS-Word 文件,但这仅限于 Word 2003 及更高版本。
例如,下面的 XML 是保存在 Word XML 文件中的空文档。
您可能不需要上面看到的所有项目,但这是可行的。
Considering the fact that MS Word can read HTML just right out of the box, you could simply change the
Response.ContentType
toapplication/ms-word
.However, if what you want is to create a
.doc
file, you might want to take a look in Office Automation.Other way is to create an XML MS-Word file, but that limits you to Word 2003 and up.
For instance the XML below is an Empty document saved in word XML file.
You may not need all the items seen above, but it's feasible.
您可以将页面标题中的内容类型更改为 application/vnd.ms-word,这应该可以解决问题,这当然是最简单的方法,我相信还有其他方法。
You could change the content type in your page header to application/vnd.ms-word, that should do the trick, this of course is the simplest way, I am sure there are others.
您可以使用 Office 自动化或尝试自己生成本机文件格式。不过,我建议使用专门的库来完成这项工作。我自己使用了一个库来进行 Excel 导出,并且有一个合适的 .NET 对象模型来操作,而不是了解本机文件结构,这很好。节省大量时间和工作。 Aspose 可能有适合您的组件或库。
You can use Office automation or try to generate in the native file format yourself. However, I can recommend using a specialized library for this work. I've used a library myself for Excel export, and it is nice to have a suitable .NET object model to manipulate, instead of knowing the native file structure. Saves a lot of time and work. Aspose might have the right component or library for you.