Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(DateTime.Now.ToString("yyyy-MM-dd") + ".xls");
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
Response.ContentType = "application/vnd.ms-excel";
string strStyle = "<style>td{mso-number-format:\"\\@\";}</style>";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
stringWrite.WriteLine(strStyle);
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
P_GridView.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();*/
/////////////////////
//*********************重新设置
P_GridView.AllowPaging = false;
P_GridView.AllowSorting = false;
this.P_GridView.PageSize = 65000;//最大为65535
dataBind();
P_GridView.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
this.P_GridView.PageSize = 10;
dataBind();
Response.AddHeader("content-disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(DateTime.Now.ToString("yyyy-MM-dd") + ".xls");
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
Response.ContentType = "application/vnd.ms-excel";
string strStyle = "<style>td{mso-number-format:\"\\@\";}</style>";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
stringWrite.WriteLine(strStyle);
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
P_GridView.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();*/
/////////////////////
//*********************重新设置
P_GridView.AllowPaging = false;
P_GridView.AllowSorting = false;
this.P_GridView.PageSize = 65000;//最大为65535
dataBind();
P_GridView.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
this.P_GridView.PageSize = 10;
dataBind();
最重要的就是下面两行
string strStyle = "<style>td{"\\@\";}</style>";//写入方式
stringWrite.WriteLine(strStyle);//使用定义的strStyle方式写入