System.IO.FileStream fs = new System.IO.FileStream(“文件路径”, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] bFile = new byte[fs.Length];
System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
bFile = r.ReadBytes((int)fs.Length);
r.Close();
r = null;
fs.Close();
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(“导出文件名称.xls”)); //把 attachment 改为 online 则在线打开
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//utf-8
Response.ContentType = "application/ms-excel";
Page.EnableViewState = false;
Response.BinaryWrite(bFile);
Response.Flush();
Response.End();