0
我正在使用以下代碼將gridview轉換爲ms-excel格式。問題是這樣的,如果我使用下面的代碼一個第一頁被轉換成MS-ecxel將gridview與分頁轉換爲excel時出錯
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();
請做要緊的變化在我的代碼,這樣我可以有cnvert分頁到Excel中。在此先感謝我的GridView。