Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void Export(HttpResponse httpResponse, IWorkbook workBook, string fileName)
- {
- httpResponse.Clear();
- MemoryStream ms = new MemoryStream();
- workBook.Write(ms);
- if (fileName.ToLower().EndsWith(".xls"))
- httpResponse.ContentType = "application/vnd.ms-excel";
- else if (fileName.ToLower().EndsWith(".xlsx"))
- httpResponse.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- else
- throw new Exception("未知的檔案格式");
- httpResponse.AddHeader("content-disposition", "attachment; filename=" + fileName);
- httpResponse.BinaryWrite(ms.ToArray());
- httpResponse.Flush();
- httpResponse.End();
- workBook = null;
- ms.Close();
- ms.Dispose();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement