這個在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 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,就會出現編碼的問題,當添了上面那段,問題就解決了:)