濮阳杆衣贸易有限公司

主頁 > 知識庫 > asp.net導(dǎo)出Excel亂碼的原因及解決方法

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

熱門標(biāo)簽:怎樣給陜西地圖標(biāo)注顏色 福州人工智能電銷機(jī)器人加盟 電銷機(jī)器人 數(shù)據(jù) 云狐人工智能電話機(jī)器人 宿遷智能外呼系統(tǒng)排名 400電話辦理信任翰諾科技 廣州銷售外呼系統(tǒng)定制 ai電銷機(jī)器人對貸款有幫助嗎 地圖標(biāo)注多少錢一張
復(fù)制代碼 代碼如下:

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)鍵:
復(fù)制代碼 代碼如下:

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

上邊如果解決不了還可以用
復(fù)制代碼 代碼如下:

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)鍵:
復(fù)制代碼 代碼如下:

Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");

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

現(xiàn)在就能防止導(dǎo)出時候亂碼問題了
您可能感興趣的文章:
  • 直接在線預(yù)覽Word、Excel、TXT文件之ASP.NET
  • ASP.NET使用GridView導(dǎo)出Excel實(shí)現(xiàn)方法
  • asp.net導(dǎo)出excel數(shù)據(jù)的常見方法匯總
  • Asp.net導(dǎo)出Excel/Csv文本格式數(shù)據(jù)的方法
  • Asp.Net使用Npoi導(dǎo)入導(dǎo)出Excel的方法
  • asp.net使用npoi讀取excel模板并導(dǎo)出下載詳解
  • ASP.NET導(dǎo)出數(shù)據(jù)到Excel的實(shí)現(xiàn)方法
  • .Net中導(dǎo)出數(shù)據(jù)到Excel(asp.net和winform程序中)
  • asp.net生成Excel并導(dǎo)出下載五種實(shí)現(xiàn)方法
  • ASP.NET導(dǎo)出Excel打開時提示:與文件擴(kuò)展名指定文件不一致解決方法
  • asp.net中如何批量導(dǎo)出access某表內(nèi)容到word文檔
  • asp.net 按指定模板導(dǎo)出word,pdf實(shí)例代碼
  • asp.net+Ligerui實(shí)現(xiàn)grid導(dǎo)出Excel和Word的方法

標(biāo)簽:綿陽 新疆 黃南 大興安嶺 宜春 焦作 曲靖 延安

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net導(dǎo)出Excel亂碼的原因及解決方法》,本文關(guān)鍵詞  asp.net,導(dǎo)出,Excel,亂碼,的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net導(dǎo)出Excel亂碼的原因及解決方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于asp.net導(dǎo)出Excel亂碼的原因及解決方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    山西省| 崇州市| 龙岩市| 宜阳县| 当涂县| 阿拉善左旗| 银川市| 金寨县| 耿马| 晋城| 西林县| 上思县| 景洪市| 海门市| 荔波县| 平和县| 西昌市| 邮箱| 长治县| 浦城县| 章丘市| 两当县| 玉环县| 胶州市| 黎川县| 杨浦区| 克山县| 文山县| 桦川县| 吐鲁番市| 大同市| 班戈县| 肥西县| 长阳| 莒南县| 讷河市| 宝应县| 都安| 台南县| 铜川市| 阿城市|