- public override void VerifyRenderingInServerForm(Control control)
- {
- //OverRide 为了使导出成Excel可行!
- }
- protected void CSVDownload_Click(object sender, EventArgs e)
- {
- Response.Clear();
- DataSet dsAnalysis1;
- dsAnalysis1 = creatdataset();
- GridView2.DataSource = dsAnalysis1.Tables[0].DefaultView;
- GridView2.DataBind();
- this.GridView2.Visible = true;
- Response.Clear();
- Response.Charset = "GB2312";
- Response.AddHeader("content-disposition", "attachment; filename=" + CSVfilename + "");
- Response.ContentEncoding = System.Text.Encoding.UTF8;
- Response.ContentType = "application/vnd.ms-excel.numberformat:@";
- System.IO.StringWriter stringWrite = new System.IO.StringWriter();
- System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
- GridView2.AllowPaging = false;
- GridView2.RenderControl(htmlWrite);
- stringWrite.ToString().Replace(",", "~");
- Response.Write(stringWrite.ToString().Replace(",", "~"));
- GridView2.Visible = false;
- Response.End();
- }
- protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- for (int i = 0; i < e.Row.Cells.Count; i++)
- {
- e.Row.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat: @");
- }
- }
- }