前台用GridView绑定,如果使用分页记得屏蔽掉
protected void btnEx_Click(object sender, EventArgs e)
{
string FileName = EXCEL表的默认名称 + DateTime.Now.ToShortDateString();
string style = @"<style> .text { mso-number-format:\@; } </script> ";
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + FileName + ".xls");
Response.ContentType = "application/excel";
Response.Charset = "GBK";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GBK");
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.GridView1.AllowPaging = false; //屏蔽分页
show_Bind(Convert.ToInt32(DropDownList1.SelectedValue));//绑定数据
this.GridView1.RenderControl(htw);
this.GridView1.Dispose();
Response.Write(style);
Response.Write(sw.ToString());
Response.End();
}