1 Public voidDgtoexcel ()2 {3 response.clearcontent ();4Response.Charset ="GB2312";//content Encoding5Response.ContentType ="Application/ms-excel";6response.contentencoding = System.Text.Encoding.GetEncoding ("GB2312");//content Encoding7Response.AddHeader ("content-disposition","attachment;filename="+ Httputility.urlencode ("Repair Parts Summary"+ System.DateTime.Now.ToShortDateString (), System.Text.Encoding.GetEncoding ("UTF-8")) +". xls");//Export File name encoding8System.IO.StringWriter SW =NewSystem.IO.StringWriter ();9HtmlTextWriter HTW =NewHtmlTextWriter (SW);Ten Gri_viewsumfeebyyg.rendercontrol (HTW); OneResponse.Write (getgridtablehtml (GRI_VIEWSUMFEEBYYG));//write the data source in HTML format A Response.End (); -}
View Code
Generally speaking, Excel exported text encoding as long as two kinds of: GB2312, UTF-8.
If the export is garbled, but try to use another encoding.
In addition, it is worth noting that the compatibility of each browser is not the same, it is possible to export the IE file name is not garbled, but in Firefox above the export file name is garbled.