Advertisement
imjyb1008work

NpoiExport

Dec 3rd, 2018
1,527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. public static void Export(HttpResponse httpResponse, IWorkbook workBook, string fileName)
  2. {
  3.     httpResponse.Clear();
  4.     MemoryStream ms = new MemoryStream();
  5.     workBook.Write(ms);
  6.     if (fileName.ToLower().EndsWith(".xls"))
  7.         httpResponse.ContentType = "application/vnd.ms-excel";
  8.     else if (fileName.ToLower().EndsWith(".xlsx"))
  9.         httpResponse.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  10.     else
  11.         throw new Exception("未知的檔案格式");
  12.     httpResponse.AddHeader("content-disposition", "attachment; filename=" + fileName);
  13.     httpResponse.BinaryWrite(ms.ToArray());
  14.     httpResponse.Flush();
  15.     httpResponse.End();
  16.     workBook = null;
  17.     ms.Close();
  18.     ms.Dispose();
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement