当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net导出Excel显示中文乱码的解决方法

asp.net导出Excel显示中文乱码的解决方法

2017年12月12日  | 移动技术网IT编程  | 我要评论

屈中恒vicky,恶徒怀里的小猫咪,邪恶漫画色系全集

复制代码 代码如下:

  protected void btnexcel_click(object sender, eventargs e)
    {
        list<buflow.model.orderhistory> orderlist = dal.getorderlist2("");
        string filename = "3g流量网龄升级计划用户表";
        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>" +"手机"+ "</th><th>" + "渠道" + "</th><th>" +"时间" + "</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();
    }

 


  需要注意的是编码的问题,在输出的时候,最好加上以下语句:
 
复制代码 代码如下:

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网