Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost("excelEbom")]
- public FileResult ExcelEbom([FromBody] Books[] books)
- {
- var comlumHeadrs = new string[]
- {
- "Book Id",
- "Name",
- };
- byte[] result;
- using (var package = new ExcelPackage())
- {
- var worksheet = package.Workbook.Worksheets.Add("Current Book"); //Worksheet name
- using (var cells = worksheet.Cells[1, 1, 1, 5])
- {
- cells.Style.Font.Bold = true;
- }
- for (var i = 0; i < comlumHeadrs.Count(); i++)
- {
- worksheet.Cells[1, i + 1].Value = comlumHeadrs[i];
- }
- //Add values
- var j = 2;
- foreach (var book in books)
- {
- worksheet.Cells["A" + j].Value = book.BookId;
- worksheet.Cells["B" + j].Value = book.name;
- j++;
- }
- result = package.GetAsByteArray();
- var excelFile= new FileContentResult(result, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
- {
- FileDownloadName = "book-export.xlsx"
- };
- return excelFile;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement