老問題,網頁導出Excel問題.
Response.Clear();
Response.Charset = Request.ContentEncoding.EncodingName;//設定字符集
Response.BufferOutput = true;
Response.ContentType = "application/vnd.ms-excel";//設定導出格式
System.IO.StringWriter oSW = new System.IO.StringWriter();
HtmlTextWriter oHW = new HtmlTextWriter(oSW);
oSW.Write(value);//將數據寫入.
Response.Write(oSW.ToString());
Response.Flush();
Response.Close();
上面是一段導出Excel的代碼.
Response.Charset = Request.ContentEncoding.EncodingName;//設定字符集
這句中,不管設定什麼樣的字符集,所用的字符集都是默認的Unicode.
不管設定什麼樣的字符集,總是會導出亂碼,由什麼方法解決.