這個在asp的時候我是這麼做的,但是在ASP.Net中,還是推薦用現成的對象好,比如
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType = filetype;
//HttpContext.Current.Response.ContentType = "application/ms-Excel";//image/JPEG;text/Html;image/GIF;vnd.ms-Excel/msWord
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
gv.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End(); 回復
# re: Web導出Word需要添加頭文件 2006-08-15 23:50 堯堯
@ASPnetx
是的,我也是用現成的,這就是上面我說的,我經常導出Excel,那個函數我寫在了
Table導出為xls,doc,txt,htm方法
但如果導出Word,就會出現編碼的問題,當添了上面那段,問題就解決了:)
http://www.cnblogs.com/zjy/archive/2006/08/15/477651.Html