Response.End();
-----------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
string fileName = page.Server.MapPath(System.DateTime.Now.ToString("yyyyMMddhhmmss") + System.DateTime.Now.Millisecond.ToString() + (new Random()).Next(0, 1000).ToString() + ".xls");
FileStream fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.None);
StreamWriter swFromFile = new StreamWriter(fs, System.Text.Encoding.GetEncoding("gb2312"));
swFromFile.WriteLine(fileValue);//要写入的数据
swFromFile.Flush();
swFromFile.Close();
page.Response.Clear();
page.Response.ClearHeaders();
page.Response.Buffer = false;
page.Response.ContentType = "Application/x-msexcel";
page.Response.AppendHeader("Content-Disposition", "attachment:filename=" + page.Server.UrlEncode(System.IO.Path.GetFileName(fileName)));
page.Response.WriteFile(fileName);
page.Response.Flush();
File.Delete(fileName);
page.Response.End();