Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
using System.IO;
namespace CreateXML
{
public partial class getExcel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BuildExcel()
{
DataSet ds = new DataSet();
ds = PublicClass.OperatorSql.returnDS("select * from Equipment_Card");
GridView gv = new GridView();
gv.DataSource = ds;
gv.DataBind();
string filename = DateTime.Now.ToString("yyyyMMdd") + ".xls";
Response.AppendHeader("Content-Disposition", "attachment;filename="
+ HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ";charset=gb2312)");
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
Response.Clear();
}
protected void Button1_Click(object sender, EventArgs e)
{
BuildExcel();
}
}
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
using System.IO;
namespace CreateXML
{
public partial class getExcel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BuildExcel()
{
DataSet ds = new DataSet();
ds = PublicClass.OperatorSql.returnDS("select * from Equipment_Card");
GridView gv = new GridView();
gv.DataSource = ds;
gv.DataBind();
string filename = DateTime.Now.ToString("yyyyMMdd") + ".xls";
Response.AppendHeader("Content-Disposition", "attachment;filename="
+ HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8) + ";charset=gb2312)");
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
Response.Clear();
}
protected void Button1_Click(object sender, EventArgs e)
{
BuildExcel();
}
}
}