Guest User

Untitled

a guest
Dec 7th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. handleExport();
  4. }
  5.  
  6. void handleExport()
  7. {
  8. // ...
  9. // Code to produce spreadsheet is here...
  10. // ...
  11.  
  12. // Write the Excel spreadsheet from the MemoryStream and send it to the browser
  13. string saveAsFileName = sFileName + ".xlsx";
  14.  
  15. Response.Clear();
  16. Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  17. Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", saveAsFileName));
  18. workbook.Write(Response.OutputStream);
  19. Response.Flush();
  20. Response.Close();
  21.  
  22. Page.ClientScript.RegisterOnSubmitStatement(typeof(Page), "closePage", "window.onunload = CloseWindow();");
  23. }
Add Comment
Please, Sign In to add comment