在 ASP.NET 中创建 Word 文档并返回给用户
我需要在内存中创建一个word文档并将其返回给网络用户。 我有 OfficeOpenXml,但我无法找到创建此 Word 文档以返回给用户的好方法。我找不到太多关于如何做到这一点的信息。 必须有一种简单的方法来做到这一点。 当我探索 OfficeOpenXml 时,我只看到一大堆 Excell 内容,而没有看到任何有关 Word 的内容。 任何帮助或教程链接都会很棒。谢谢你! 这一切都在使用 C# 的 ASP.NET MVC 中
I need to create a word document in memory and return it to the web user.
I have the OfficeOpenXml but I just can't figure out a decent way of creating this word document to return to the user. And I can't find much out there on how to do this.
There has to be a simple way of doing this.
When I explore the OfficeOpenXml, I just see a whole bunch of Excell stuff and nothing about word.
Any help or links to tutorials would be great. Thank you!
This is all in asp.net MVC using C#
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是创建 Word 文档的示例 http://msdn.microsoft.com/en -us/library/bb497758.aspx 使用 OpenXML SDK(从 http://www.microsoft.com/downloads/en/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en )。有关内存中操作,请查看此博客 - http://blogs.msdn.com/b/ericwhite/archive/2008/12/10/working-with-in-memory-open-xml-documents.aspx
创建文档时,您需要将其作为响应设置适当的内容处置标头返回 - http://support.microsoft .com/kb/260519。
Here is a sample to create Word document http://msdn.microsoft.com/en-us/library/bb497758.aspx using OpenXML SDK (download from http://www.microsoft.com/downloads/en/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en). For in-memory manipulation check out this blog - http://blogs.msdn.com/b/ericwhite/archive/2008/12/10/working-with-in-memory-open-xml-documents.aspx
When you created document you need to return it as response setting content-disposition header appropriately - http://support.microsoft.com/kb/260519.
啊,你可以把它作为文件下载下来。基本上,您创建文件并将其二进制数据写入响应。您真正需要做的唯一一件事就是更改响应标头以告诉浏览器它是 DOC 而不是 HTML。
Ah, you can send it down as a file download. Basically you create the file and write it's binary data to the response. The only thing that you need to really do is change the response headers to tell the browser it is a DOC and not HTML.