我怎么可以嵌入图像生成的Word文件的ASP.NET [英] How can I embed images in an ASP.NET Generated Word File

查看:134
本文介绍了我怎么可以嵌入图像生成的Word文件的ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当普遍的问题,因为我在不同的用户组看到了也没有找到合适的答案。

I have a quite common problem, as I saw in the various user groups but could not find a suitable answer.

我想要做的就是产生在我的网站的ASP.NET页面,将有被导出到Microsoft Word .doc格式的选项。

What I want to do is generate an ASP.NET page in my website which will have the option of being exported into Microsoft Word .doc format.

我用的方法是这样的:

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Test.doc");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/msword";

StringWriter sw = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(sw);
Page.RenderControl(htmlWrite);
Response.Write(sw.ToString());
Response.End();

然而,这尽管它已经生成一个Word文档,图像是音符嵌入到文档中,而它们被放置为链接。我已经找了一个办法做到这一点,但还没有找到的东西,实际工作。

However this eventhough it generates a word doc, the images are note embedded in the document, rather they are placed as links. I have looked for a way to do this, but have not found something that actually worked.

我想AP preciate任何帮助,我可以得到的,因为这是最后一分钟的要求
(谈典型值)

I would appreciate any help I can get, since this as "last minute" requirement (talk about typical)

感谢

推荐答案

简短的回答:您需要的图像在你的页面的源代码提供绝对URL

Short Answer: You need to provide absolute URLs for the source of the images in your page.

更长的答案:

如果你带* .doc扩展名重命名该Microsoft Word中打开HTML文档。这是什么,你所提供的code在做什么。在这种情况下,图像不嵌入在文档中一样,如果所创建的实际Word格式的文档他们会。如果您的图像使用相对URL,然后Word将不知道去哪里找他们,因此需要绝对URL。

Microsoft Word will open an HTML document if you rename it with a *.doc extension. This is what the code that you provided is doing. In this case, the images are not embedded in the document like they would be if you created a document in actual Word format. If your images are using relative URLs then Word will not know where to look for them, hence the need for absolute URLs.

注:这意味着,任何人查看该文档没有互联网连接将无法看到图像,因为它们是从服务器每次打开文档时要求

一个更优雅的解决方案是建立在真正的Word格式文档。这个伟大的图书馆是<一个href=\"http://www.aspose.com/categories/file-format-components/aspose.words-for-.net-and-java/default.aspx\">Aspose.Words.使用这个库,你将能够直接嵌入图像到文档,使它们不依赖于服务器上。

A more elegant solution would be to create the document in the real Word format. A great library for this is Aspose.Words. Using this library you would be able to embed the images directly into the document so that they do not rely on the server.

这篇关于我怎么可以嵌入图像生成的Word文件的ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆