gpt4 book ai didi

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

转载 作者:qq735679552 更新时间:2022-09-29 22:32:09 26 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章asp.net导出Excel显示中文乱码的解决方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

代码如下

  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"/> 。

最后此篇关于asp.net导出Excel显示中文乱码的解决方法的文章就讲到这里了,如果你想了解更多关于asp.net导出Excel显示中文乱码的解决方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com