Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. [AllowAnonymous]
  2. public HttpResponseMessage Get()
  3. {
  4. using (ExcelPackage pck = new ExcelPackage())
  5. {
  6. ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");
  7.  
  8. ws.Cells.LoadFromText("A1,A2");
  9.  
  10. HttpResponseMessage response = new HttpResponseMessage();
  11. var s = pck.GetAsByteArray();
  12.  
  13. response.Content = new ByteArrayContent(s);
  14. response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
  15. response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
  16. response.Content.Headers.ContentDisposition.FileName = "Orders.xlsx";
  17. response.Content.Headers.ContentLength = s.LongLength;
  18. response.StatusCode = HttpStatusCode.OK;
  19.  
  20. return response;
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement