Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [AllowAnonymous]
- public HttpResponseMessage Get()
- {
- using (ExcelPackage pck = new ExcelPackage())
- {
- ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");
- ws.Cells.LoadFromText("A1,A2");
- HttpResponseMessage response = new HttpResponseMessage();
- var s = pck.GetAsByteArray();
- response.Content = new ByteArrayContent(s);
- response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
- response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
- response.Content.Headers.ContentDisposition.FileName = "Orders.xlsx";
- response.Content.Headers.ContentLength = s.LongLength;
- response.StatusCode = HttpStatusCode.OK;
- return response;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement