国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net導(dǎo)出Excel亂碼的原因及解決方法

2024-07-10 12:43:38
字體:
供稿:網(wǎng)友
代碼如下:
protected void Excel_Click(object sender, EventArgs e)
{
Response.Charset = "UTF-8";
Response.ClearContent();
Response.Clear();
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.HeaderEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("content-disposition", "attachment; filename=MyExpress.xls");
Response.ContentType = "application/excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
// turn off paging
GridView1.AllowPaging = false;
dataBind();
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
// turn the paging on again
GridView1.AllowPaging = true;
dataBind();
}

關(guān)鍵:
代碼如下:
Response.Charset = "UTF-8";//添加編碼格式
Response.ClearContent();
Response.Clear();
Response.ContentEncoding = System.Text.Encoding.UTF8;//表格內(nèi)容添加編碼格式
Response.HeaderEncoding = System.Text.Encoding.UTF8;//表頭添加編碼格式

上邊如果解決不了還可以用
代碼如下:
Response.ClearContent();
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=sumlate.xls");
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
if (GridView2.Rows.Count > 0)
{
GridView2.RenderControl(htw);
}
else
{
GridView1.RenderControl(htw);
}
Response.Write(sw.ToString());
Response.End();

關(guān)鍵:
代碼如下:
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

注意觀察,主要原因其實(shí)就是編碼格式問題。

現(xiàn)在就能防止導(dǎo)出時(shí)候亂碼問題了
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 东城区| 隆德县| 浑源县| 吉安县| 满城县| 泽州县| 揭东县| 木兰县| 崇明县| 扎兰屯市| 察雅县| 寿光市| 旬阳县| 东辽县| 永登县| 新沂市| 辽阳市| 壶关县| 孟州市| 阜城县| 石河子市| 循化| 漳浦县| 财经| 枞阳县| 太保市| 淮滨县| 克拉玛依市| 竹北市| 盱眙县| 嘉禾县| 平罗县| 肇东市| 永州市| 临清市| 河津市| 宁阳县| 秦皇岛市| 遂溪县| 彭阳县| 开原市|