public ActionResult PrintAtt(string code, string date) { string fileName = "Bang_diem_danh_" + date + ".xlsx"; string content = _attdSrv.GetDataActice(Convert.ToInt64(code)).Content; DataTable data = _attdSrv.GetDataTableToPrint(Convert.ToInt64(code)); 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()) { string caption = ""; ExcelWorksheet workSheet = pck.Workbook.Worksheets.Add("Gio Cong Tac Khac"); FunctionUtility.DataTableToExcelAtt(workSheet, data, date, content); var ms = new System.IO.MemoryStream(); pck.SaveAs(ms); return(File(ms.ToArray(), "application/vnd.ms-excel", fileName)); } }