下面是导出方法的代码 private void WriteFile(string str_fileName, Stream stream) { HttpContext.Current.Response.Clear(); HttpRequest _Request = HttpContext.Current.Request; HttpResponse _Response = HttpContext.Current.Response; BinaryReader br = new BinaryReader(stream); _Response.AddHeader("Accept-Ranges", "bytes"); _Response.Buffer = false; long fileLength = stream.Length; long startBytes = 0; int pack = 10240; //10K bytes //int sleep = 200; //每秒5次 即5*10K bytes每秒 int sleep = (int)Math.Floor(Convert.ToDouble(1000 * pack / 1024000)) + 1; if (_Request.Headers["Range"] != null) { _Response.StatusCode = 206; string[] range = _Request.Headers["Range"].Split(new char[] { '=', '-' }); startBytes = Convert.ToInt64(range[1]); } _Response.AddHeader("Content-Length", (fileLength - startBytes).ToString()); if (startBytes != 0) { _Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength - 1, fileLength)); } _Response.AddHeader("Connection", "Keep-Alive"); _Response.ContentType = "application/vnd.ms-excel"; _Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(str_fileName, System.Text.Encoding.UTF8)); br.BaseStream.Seek(startBytes, SeekOrigin.Begin); int maxCount = (int)Math.Floor(Convert.ToDouble((fileLength - startBytes) / pack)) + 1; for (int i = 0; i < maxCount; i++) { if (_Response.IsClientConnected) { _Response.BinaryWrite(br.ReadBytes(pack)); Thread.Sleep(sleep); } else { i = maxCount; } } }
好吧,换了一种公司框架已经封装好了的导出方法就可以了
好像是使用的HSSFWorkbook
不说用什么技术,没有代码,不说怎么实现的导出,emmmmmmmmm。。。
第一次提问有点小紧张,代码已附上
@心判世界: 你的stream怎么来的?
@顾晓北: 就是一个datatable遍历拼接成html字符串再转换成流
@心判世界: 那就跟提示一样了,这种Excel你自己看还行,不是标准的Excel,标准的ms Excel会有一些其他的信息。。。
建议使用插件,aspose