(C#)asp.net(DataSet)导出Excel文件

  1. public override void VerifyRenderingInServerForm(Control control)
  2.     {
  3.         //OverRide 为了使导出成Excel可行!
  4.     }
  5.     protected void CSVDownload_Click(object sender, EventArgs e)
  6.     {
  7.         Response.Clear();
  8.         DataSet dsAnalysis1;
  9.         dsAnalysis1 = creatdataset();
  10.         GridView2.DataSource = dsAnalysis1.Tables[0].DefaultView;
  11.         GridView2.DataBind();
  12.         this.GridView2.Visible = true;
  13.          Response.Clear();
  14.         Response.Charset = "GB2312";
  15.         Response.AddHeader("content-disposition""attachment; filename=" + CSVfilename + "");
  16.         Response.ContentEncoding = System.Text.Encoding.UTF8;
  17.         Response.ContentType = "application/vnd.ms-excel.numberformat:@";
  18.         System.IO.StringWriter stringWrite = new System.IO.StringWriter();
  19.         System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
  20.         GridView2.AllowPaging = false;
  21.         GridView2.RenderControl(htmlWrite);
  22.         stringWrite.ToString().Replace(",""~");
  23.         Response.Write(stringWrite.ToString().Replace(",""~"));
  24.         GridView2.Visible = false;
  25.         Response.End();
  1.     }
  2.     protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
  3.     {
  4.         if (e.Row.RowType == DataControlRowType.DataRow)
  5.         {
  6.             for (int i = 0; i < e.Row.Cells.Count; i++)
  7.             {
  8.                 e.Row.Cells[i].Attributes.Add("style""vnd.ms-excel.numberformat: @");
  9.             }
  10.         }
  11.     }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值