读书人

向高手请问一个关于导出到Word的有关问

发布时间: 2012-02-11 09:51:35 作者: rapoo

向高手请教一个关于导出到Word的问题
我用下面这种方式将页面导出到Word时背景图片导不出来是怎么回事?
string fileName = string.Empty;
if (string.IsNullOrEmpty(fileName))
{
fileName = "著作工作量分配单";
}
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.Page.Form.RenderControl(htw);
string pageHtml = sw.ToString();
int startIndex = pageHtml.IndexOf("<div id=\"Print\"");
int endIndex = pageHtml.LastIndexOf("</div>");
int lenth = endIndex - startIndex;
pageHtml = pageHtml.Substring(startIndex, lenth);
pageHtml = pageHtml.Remove(pageHtml.LastIndexOf("<div>"));
HttpContext context = HttpContext.Current;
context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + ".doc");
context.Response.ContentType = "application/ms-word";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.Charset = "UTF8";
context.Response.Write(pageHtml);
context.Response.End();

[解决办法]
mark
[解决办法]

读书人网 >asp.net

热点推荐