当前位置:编程学习 > C#/ASP.NET >>

asp.net导出word文档,图片无法显示,怎么解决。

用的一下方式实现的导出word,但是图片无法显示 
public void ExportToWord()
        {

            string content = HttpContext.Current.Request.QueryString["content"];

            string ExportFileName = DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + "试卷";
            string filename = HttpUtility.UrlEncode(ExportFileName, System.Text.UnicodeEncoding.GetEncoding("GB2312"));
            //ExportToWord(Server.UrlDecode(content), filename);

            //定义文档类型、字符编码
            System.Web.HttpContext.Current.Response.Charset = "GB2312";
            //attachment 参数表示作为附件下载,您可以改成 online在线打开
            //filename 指定输出文件的名称,注意其扩展名和指定文件类型相符,可以为:.doc .xls .txt .htm
            System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".doc");
            System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            //Response.ContentType指定文件类型 可以为application/ms-excel、application/ms-word、application/ms-txt、application/ms-html 或其他浏览器可直接支持文档
            System.Web.HttpContext.Current.Response.ContentType = "application/ms-word";

            System.IO.StringWriter tw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw);


            Page.EnableViewState = false;
            RenderControl(hw);

            StringBuilder head = new StringBuilder();
            head.Append("<html xmlns:v=\"urn:schemas-microsoft-com:vml\"  ");
            head.Append(" xmlns:o=\"urn:schemas-microsoft-com:office:office\"  ");
            head.Append("xmlns:w=\"urn:schemas-microsoft-com:office:word\"  ");
            head.Append("xmlns:m=\"http://schemas.microsoft.com/office/2004/12/omml\"");
            head.Append("xmlns=\"http://www.w3.org/TR/REC-html40\">");
            string foot = "</html> ";

            System.Web.HttpContext.Current.Response.Write(head.ToString() + content + foot);
            System.Web.HttpContext.Current.Response.End();

        }
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,