时间:2021-05-28
复制代码 代码如下:
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"/>
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
asp.net针对Excel文件的导入与导出是非常常见的功能之一。本文实例讲述了Asp.Net使用Npoi导入导出Excel的方法。分享给大家供大家参考之用。具
在做ASP.NET开发的时候,参数传递中文时,经常会遇到页面乱码的问题,解决的方法一般有3种: 1.设置web.config文件............
本文实例讲述了asp.net实现导出DataTable数据到Word或者Excel的方法。分享给大家供大家参考,具体如下:///<xmlnamespacepre
本文实例讲述了asp.net实现Gradview绑定数据库数据并导出Excel的方法。分享给大家供大家参考,具体如下:protectedvoidshowData
iis6安装了asp.net,但是网站属性中没有显示asp.net选项卡。解决办法如下:1,如果是只安装了.netframework1.1在iis中是不显示那个