public void ExportToExcel() { var personModels = _persons.GetAll(); var listingResult = personModels.Select(result => new PersonIndexListingModel { Id = result.Id, Marca = result.Marca, Nume = result.Nume, Prenume = result.Prenume, DataNastere = result.DataNastere, Sex = result.Sex, Nationalitate = result.Nationalitate, Email = result.Email }); var model = new PersonIndexModel() { Persons = listingResult }; ExcelPackage.LicenseContext = LicenseContext.NonCommercial; ExcelPackage pck = new ExcelPackage(); ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Raport persoane"); ws.Cells["A1"].Value = "Marca"; ws.Cells["B1"].Value = "Nume"; ws.Cells["C1"].Value = "Prenume"; ws.Cells["D1"].Value = "Data nasterii"; ws.Cells["E1"].Value = "Sex"; ws.Cells["F1"].Value = "Nationalitate"; ws.Cells["G1"].Value = "Email"; int rowStart = 2; foreach (var person in model.Persons) { ws.Cells[string.Format("A{0}", rowStart)].Value = person.Marca; ws.Cells[string.Format("B{0}", rowStart)].Value = person.Nume; ws.Cells[string.Format("C{0}", rowStart)].Value = person.Prenume; ws.Cells[string.Format("D{0}", rowStart)].Value = string.Format("{0:dd MMMM yyyy}", person.DataNastere); ws.Cells[string.Format("E{0}", rowStart)].Value = person.Sex; ws.Cells[string.Format("F{0}", rowStart)].Value = person.Nationalitate; ws.Cells[string.Format("G{0}", rowStart)].Value = person.Email; rowStart++; } ws.Cells["A:AZ"].AutoFitColumns(); Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.Headers.Add("content-disposition", "attachment: filename=" + "ExcelReport.xlsx"); Response.Body.Write(pck.GetAsByteArray()); }
// GET: Person public ActionResult Index(PersonIndexModel model) { if (model == null) { model = new PersonIndexModel(); } if (model.LastName == null) { model.LastName = string.Empty; } model.People = _repository.GetPersonList(model.LastName); return(View(model)); }
public IActionResult Index() { List <Person> allPersons = _person.Getall().ToList(); IEnumerable <PersonDetailModel> PersonModels; // if (allPersons.Any()) // { PersonModels = Mapper.Map <List <Person>, List <PersonDetailModel> >(allPersons); var model = new PersonIndexModel() { People = PersonModels }; return(View(model)); // } // return RedirectToAction("Index", "Home"); }
public IActionResult Index() { var personModels = _persons.GetAll(); var listingResult = personModels.Select(result => new PersonIndexListingModel { Id = result.Id, Marca = result.Marca, Nume = result.Nume, Prenume = result.Prenume, DataNastere = result.DataNastere, Sex = result.Sex, Nationalitate = result.Nationalitate, Email = result.Email }); var model = new PersonIndexModel() { Persons = listingResult }; return(View(model)); }