Exemplo n.º 1
0
        public ActionResult PrintThongKe(int year)
        {
            string    mgv      = Session["UserCode"].ToString();
            string    role     = Session["UserRole"].ToString();
            string    name     = Session["UserName"].ToString();
            string    fileName = name + "_gio_cong_tac_khac.xlsx";
            DataTable data     = _statisticSrv.GetDataTableThongkecanhan(mgv, year);

            if (data == null)
            {
                var            streamNull = new System.IO.MemoryStream();
                ExcelPackage   pck        = new ExcelPackage();
                ExcelWorksheet p          = pck.Workbook.Worksheets.Add("Gio Cong Tac Khac");
                pck.SaveAs(streamNull);
                return(File(streamNull.ToArray(), "application/octet-stream", fileName));
            }
            using (ExcelPackage pck = new ExcelPackage())
            {
                ExcelWorksheet workSheet = pck.Workbook.Worksheets.Add("Gio Cong Tac Khac");
                FunctionUtility.DataTableToExcelThongKe(workSheet, data, 2018, name, role);
                var ms = new System.IO.MemoryStream();
                pck.SaveAs(ms);
                return(File(ms.ToArray(), "application/vnd.ms-excel", fileName));
            }
        }