将带有图像的Gridview导出到Excel - 问题

时间:2009-08-14 07:31:48

标签: asp.net image export-to-excel

我在ASP.NET C#Page中有一个Gridview。它有几列和一个图像列。我可以将整列导出到Excel文件,但image列为空。顺便说一下,我使用完整的路径。

任何想法?

2 个答案:

答案 0 :(得分:2)

是default.aspx中的是(对于本地导出)

ImageUrl="http://localhost:4056/CSharp/banner.gif"
instead of ImageUrl="~/banner.gif"

或(用于远程导出)

http://your ip address here :port/foldername/filename

答案 1 :(得分:0)

Response.Clear(); //这将清除任何标头或先前输出的响应         Response.Buffer = true; //确保同时呈现整个输出

    Response.ContentType = "application/vnd.ms-excel";
    StringWriter stringWriter = new StringWriter(); //System.IO namespace should be used

    HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
    GridView2.GridLines = GridLines.Both;
    GridView2.RenderControl(htmlTextWriter);
    Response.Write(stringWriter.ToString());
    Response.End();