示例#1
0
        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());
        }
示例#2
0
        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"));
                }
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
        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));
        }