婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

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

asp.net導出Excel亂碼的原因及解決方法

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

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();
}

關鍵:
復制代碼 代碼如下:

Response.Charset = "UTF-8";//添加編碼格式
Response.ClearContent();
Response.Clear();
Response.ContentEncoding = System.Text.Encoding.UTF8;//表格內容添加編碼格式
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();

關鍵:
復制代碼 代碼如下:

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

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

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

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

巨人網(wǎng)絡通訊聲明:本文標題《asp.net導出Excel亂碼的原因及解決方法》,本文關鍵詞  asp.net,導出,Excel,亂碼,的,;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《asp.net導出Excel亂碼的原因及解決方法》相關的同類信息!
  • 本頁收集關于asp.net導出Excel亂碼的原因及解決方法的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 定日县| 齐河县| 射洪县| 衡南县| 凤阳县| 新野县| 曲阳县| 荥阳市| 长寿区| 滦南县| 喀喇沁旗| 贺州市| 仙桃市| 乌兰浩特市| 凌云县| 克拉玛依市| 灵台县| 镇坪县| 彭州市| 顺昌县| 安泽县| 敦煌市| 墨竹工卡县| 湖北省| 荆州市| 舞钢市| 称多县| 易门县| 娄底市| 侯马市| 达尔| 随州市| 成安县| 常山县| 西盟| 萍乡市| 高雄县| 临夏市| 望都县| 铜鼓县| 齐河县|