public ActionResult ExportToWord() { lear db = new lear(); // get the data from database var data = db.Certifications.ToList(); // instantiate the GridView control from System.Web.UI.WebControls namespace // set the data source GridView gridview = new GridView(); gridview.DataSource = data; gridview.DataBind(); // Clear all the content from the current response Response.ClearContent(); Response.Buffer = true; // set the header Response.AddHeader("content-disposition", "attachment;filename = Certificate.doc"); Response.ContentType = "application/ms-word"; Response.Charset = ""; // create HtmlTextWriter object with StringWriter using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { // render the GridView to the HtmlTextWriter gridview.RenderControl(htw); // Output the GridView content saved into StringWriter Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } } return(View()); }
public FileResult ExportToExcel() { lear entities = new lear(); DataTable dt = new DataTable("Grid"); dt.Columns.AddRange(new DataColumn[4] { new DataColumn("Id"), new DataColumn("Code"), new DataColumn("Description"), new DataColumn("Points") }); var certificates = from Certification in entities.Certifications select Certification; foreach (var certificate in certificates) { dt.Rows.Add(certificate.Id, certificate.Code, certificate.Description, certificate.Points); } using (XLWorkbook wb = new XLWorkbook()) { wb.Worksheets.Add(dt); using (MemoryStream stream = new MemoryStream()) { wb.SaveAs(stream); return(File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Certificates.xlsx")); } } }
public ActionResult PrintPartialViewToPdf(int id) { using (lear db = new lear()) { Certification customer = db.Certifications.FirstOrDefault(c => c.Id == id); var report = new PartialViewAsPdf("~/Views/Shared/DetailCustomer.cshtml", customer); return(report); } }
public ActionResult Certificates() { lear dbconext = new lear(); CertificatesViewModel model = new CertificatesViewModel(); var certificates = dbconext.Certifications.ToList <Certification>(); foreach (var cert in certificates) { System.Diagnostics.Debug.WriteLine(cert.Description); model.Certifications.Add(new Certification() { Id = cert.Id, Code = cert.Code, Description = cert.Description, Points = cert.Points }); } return(View(model)); }