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

首頁(yè) > 編程 > .NET > 正文

asp.net導(dǎo)出Excel顯示中文亂碼的解決方法

2024-07-10 13:17:14
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

復(fù)制代碼 代碼如下:


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

 


  需要注意的是編碼的問(wèn)題,在輸出的時(shí)候,最好加上以下語(yǔ)句:
 

復(fù)制代碼 代碼如下:


<meta http-equiv="content-type" content="application/ms-excel; charset=gb2312"/>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 高雄市| 公安县| 通江县| 同心县| 桓台县| 梨树县| 鸡西市| 南丹县| 黄浦区| 瑞丽市| 蚌埠市| 布尔津县| 祁阳县| 唐海县| 南昌县| 灵山县| 大兴区| 通州区| 青铜峡市| 城步| 钟山县| 宁化县| 疏勒县| 泽普县| 洞口县| 龙泉市| 江源县| 金沙县| 垦利县| 新竹县| 松原市| 宁津县| 马龙县| 伊金霍洛旗| 福安市| 淮南市| 大厂| 常德市| 裕民县| 万盛区| 郸城县|