我使用以下代码将gridview转换为ms-excel格式。问题是如果我使用以下代码,第一页转换为ms-ecxel
protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
string file1 = TextBox1.Text + ".xls";
string attachment = string.Format("attachment;filename={0}", file1);
this.EnableViewState = false;
Response.AddHeader("content-disposition", attachment);
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/ms-excel";
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
}
并且如果将这两行添加到我的代码中,我将得到空白的ms-excel表
GridView1.AllowPaging = false;
this.Emp_Wrklog();
请对我的代码进行必要的更改,以便我可以将我的gridview转换为excel。提前谢谢。