导出到EXCEL

private   void  Button2_Click( object  sender, System.EventArgs e)
{
DateTime dt;
if(this.Search_Time.Text ==null || this.Search_Time.Text =="")
{
dt            
=   DateTime.Now;
}

else
{
dt           
=   Convert.ToDateTime(this.Search_Time.Text.ToString());
}

this.UpStartDay  =  dt.ToString("yyyy-MM-dd");
string Nums      =  Admin_Bonus.Get_Count(this.UpStartDay,1);//总碰数的统计
string ZZHD      =  Admin_Bonus.Get_Count(this.UpStartDay,2);//组织互动的统计
string FDDD      =  Admin_Bonus.Get_Count(this.UpStartDay,3);//辅导对等的统计
string HJ        =  Convert.ToDouble(System.Math.Round(Convert.ToDouble(ZZHD),2)+System.Math.Round(Convert.ToDouble(FDDD),2)).ToString();
DataSet ds 
= new DataSet();
ds 
= Admin_Bonus.Get_DateSet(this.UpStartDay);
this.BonusList.DataSource = ds;
this.BonusList.DataBind();
Response.AddHeader(
"Content-Type""application/vnd.ms-excel");
Response.AddHeader(
"Content-Disposition""attachment;filename=Day~JJMX~"+this.UpStartDay.ToString()+".xls");
Response.Charset 
= "";
ResponseEncoding
="utf-8";//以此编码模式导出才不会出现乱码

            
//关闭 ViewState
EnableViewState = false;
System.IO.StringWriter tw 
= new System.IO.StringWriter();//将信息写入字符串
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);//在WEB窗体页上写出一系列连续的HTML特定字符和文本。
            
//此类提供ASP.NET服务器控件在将HTML内容呈现给客户端时所使用的格式化功能
            
//获取control的HTML
hw.WriteLine("<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#a9cb34" class="table">");
hw.WriteLine(
"<tr height="18" bgcolor="#f5fce0">");
hw.WriteLine(
"<td colspan=8 width="71%" align="center" class="xtd">各项统计</td>");
hw.WriteLine(
"<td width="5%" align="center" class="xtd">"+Nums.ToString()+"</td>");
hw.WriteLine(
"<td width="9%" align="center" class="xtd">"+ZZHD.ToString()+"</td>");
hw.WriteLine(
"<td width="8%" align="center" class="xtd">"+FDDD.ToString()+"</td>");
hw.WriteLine(
"<td width="7%" align="center" class="xtd">"+HJ.ToString()+"</td>");
BonusList.RenderControl(hw);
//将DATAGRID中的内容输出到HtmlTextWriter对象中
            
// 把HTML写回浏览器
Response.Write(tw.ToString());
Response.End();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值