C# Excel导出后台代码

FileStream fileStrem = new FileStream(templatePath, FileMode.Open);
                                                                 long fileSize = fileStrem.Length;
                                                                 Context.Response.ContentType = "application/octet-stream";
                                                                 Context.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("任务模板.xlsx", Encoding.UTF8));
                                                                 Context.Response.AddHeader("Content-Length", fileSize.ToString());
                                                                 byte[] fileBuffer = new byte[fileSize];
                                                                 fileStrem.Read(fileBuffer, 0, (int)fileSize);
                                                                 Context.Response.BinaryWrite(fileBuffer);
                                                                 Context.Response.End();

  

posted @ 2014-07-15 11:19  Toby Wang  阅读(431)  评论(0编辑  收藏  举报