[controller class] [AcceptVerbs(HttpVerbs.Post)] public ActionResult ExcelPackageCreate(string id) { try { FileInfo template = new FileInfo(Server.MapPath(@"\Content\ExcelPackageTemplate.xlsx")); FileInfo newFile = new FileInfo(Server.MapPath(@"\Content\ExcelPackageNewFile.xlsx")); // Using the template to create the newFile... using(ExcelPackage excelPackage = new ExcelPackage(newFile, template)) { // Getting the complete workbook... ExcelWorkbook myWorkbook = excelPackage.Workbook; // Getting the worksheet by its name... ExcelWorksheet myWorksheet = myWorkbook.Worksheets["Sheet1"]; // Setting the value 77 at row 5 column 1... myWorksheet.Cell(5, 1).Value = 77.ToString(); // Saving the change... excelPackage.Save(); } TempData["Message"] = "Excel report created successfully!"; return RedirectToAction("ExcelPackage"); } catch(Exception ex) { TempData["Message"] = "Oops! Something went wrong."; return RedirectToAction("ExcelPackage"); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)