日期:2014-05-18  浏览次数:20379 次

.net输出Excel时中文出现乱码
我用.net输出Excel出现乱码?
当数据量小的时候,全部正常.

当数据量较大时,所有的中文字符都出现乱码.

代码如下:
Response.Clear();
                Response.AddHeader( "content-disposition ",   "attachment;filename= "   +   (DateTime.Now.ToShortDateString()   +   "- "   +   DateTime.Now.Hour   +   DateTime.Now.Minute   +   DateTime.Now.Second   +   ".xls "));
                Response.Charset   =   "UTF-7 ";
                Response.Buffer   =   true;
                Response.ContentEncoding   =   System.Text.Encoding.Default;
                Response.ContentType   =   "application/vnd.xls ";
                string   str   =   app_Excel.MeasureDataToExcel(TrainCode,   LocomotiveModelAndCode,   LocomotiveDepotName,   Direction,   DriveDate,   ds.Tables[0]);
                Response.Write(str);
                Response.End();


Web.config   设置如下:
<globalization   uiCulture= "zh-CN "   culture= "zh-CN "   requestEncoding= "GB2312 "   responseEncoding= "GB2312 "   fileEncoding= "GB2312 "/>


------解决方案--------------------
关键在这里
Response.Charset = "UTF-7 ";
Response.Buffer = true;
Response.ContentEncoding = System.Text.Encoding.Default;
自己试试!
------解决方案--------------------
Response.Charset = "gb2312 ";
Response.Buffer = true;
Response.ContentEncoding = System.Text.Encoding.Default;
这样行不行 我也遇到过
------解决方案--------------------
Response.Charset这个多换几种试试,要嘛不要它采用默认的看看