asp.net導(dǎo)出Excel顯示中文亂碼的解決方法
protected void btnExcel_Click(object sender, EventArgs e)
{
List<bUFlow.Model.orderhistory> orderlist = dal.GetOrderList2("");
string filename = "3g流量網(wǎng)齡升級(jí)計(jì)劃用戶表";
string name1 = filename;
string bname = Common.MyRequest.GetBrowserName().ToLower();
if (bname.Contains("firefox"))
{
}
else if (bname.Contains("ie"))
{
filename = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);
}
else
{
filename = HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);
}
HttpResponse resp = System.Web.HttpContext.Current.Response;
resp.Charset = "utf-8";
resp.Clear();
resp.AppendHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
resp.ContentEncoding = System.Text.Encoding.UTF8;
resp.ContentType = "application/ms-excel";
string style ="<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=utf-8\"/>"+ "<style> .table{ font: 9pt Tahoma, Verdana; color: #000000; text-align:center; background-color:#8ECBE8; }.table td{text-align:center;height:21px;background-color:#EFF6FF;}.table th{ font: 9pt Tahoma, Verdana; color: #000000; font-weight: bold; background-color: #8ECBEA; height:25px; text-align:center; padding-left:10px;}</style>";
resp.Write(style);
//resp.Write(ExportTable(list));
resp.Write("<table class='table'><tr><th>" +"手機(jī)"+ "</th><th>" + "渠道" + "</th><th>" +"時(shí)間" + "</th></tr>");
//dbVideoList = (List<subShiyongModel>)Session["dbVideoList"];
foreach (bUFlow.Model.orderhistory model in orderlist)
{
resp.Write("<tr><td>" + model.phone + "</td>");
resp.Write("<td>" + model.qudao + "</td>");
resp.Write("<td>" + model.tm + "</td>");
resp.Write("</tr>");
}
resp.Write("<table>");
resp.Flush();
resp.End();
}
需要注意的是編碼的問題,在輸出的時(shí)候,最好加上以下語句:
<meta http-equiv="content-type" content="application/ms-excel; charset=gb2312"/>
相關(guān)文章
VS2017 Cordova Ionic2 移動(dòng)開發(fā)環(huán)境搭建教程
這篇文章主要為大家詳細(xì)介紹了VS2017 Cordova Ionic2 移動(dòng)開發(fā)環(huán)境搭建教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
.Net使用RabbitMQ即時(shí)發(fā)消息Demo
RabbitMQ是一個(gè)在AMQP基礎(chǔ)上完整的,可復(fù)用的企業(yè)消息系統(tǒng),下面這篇文章主要給大家介紹了關(guān)于.Net使用RabbitMQ即時(shí)發(fā)消息的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-07-07
.net動(dòng)態(tài)顯示當(dāng)前時(shí)間(客戶端javascript)
剛才在首頁看到 asp.net實(shí)現(xiàn)動(dòng)態(tài)顯示當(dāng)前時(shí)間 這篇文章, 作者用Ajax實(shí)現(xiàn)類似時(shí)鐘的效果!2009-11-11
vs.net 2010 擴(kuò)展插件小結(jié) 提高編程效率
本文價(jià)紹了幾款Visual Studio提供的插件,提高我們的編程效率。2011-03-03
asp.net(vb)實(shí)現(xiàn)金額轉(zhuǎn)換成大寫的函數(shù)
asp.net(vb)實(shí)現(xiàn)金額轉(zhuǎn)換成大寫的函數(shù)代碼,需要的朋友可以參考下。2011-10-10
微軟發(fā)布的Data Access Application Block的使用代碼
微軟發(fā)布的Data Access Application Block的使用代碼...2007-04-04
asp.net 生成數(shù)字和字母組合的隨機(jī)數(shù)
asp.net下生成數(shù)字跟字母組合的隨機(jī)數(shù),提高驗(yàn)證安全。2009-03-03
Entity Framework使用Code First模式管理視圖
本文詳細(xì)講解了Entity Framework使用Code First模式管理視圖的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03

