public ActionResult Export(IngredientModel model, bool isExport = true) { try { //IngredientModel model = new IngredientModel(); XLWorkbook wb = new XLWorkbook(); var wsIngredient = wb.Worksheets.Add("Ingredients"); var wsIngredientUOM = wb.Worksheets.Add("IngredientUOM"); var wsIngredientSupplier = wb.Worksheets.Add("IngredientSupplier"); var data = _factory.Export(ref wsIngredient, ref wsIngredientUOM, ref wsIngredientSupplier, model.ListCompany, lstCompany); if (!data.IsOk) { ModelState.AddModelError("ingredient", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(data.Message)); return(View(data)); } ViewBag.wb = wb; Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.Charset = UTF8Encoding.UTF8.WebName; Response.ContentEncoding = UTF8Encoding.UTF8; Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; string fileName = CommonHelper.GetExportFileName("Ingredients").Replace(" ", "_"); Response.AddHeader("content-disposition", String.Format(@"attachment;filename={0}.xlsx", fileName)); using (var memoryStream = new System.IO.MemoryStream()) { wb.SaveAs(memoryStream); memoryStream.WriteTo(HttpContext.Response.OutputStream); memoryStream.Close(); } HttpContext.Response.End(); ViewBag.IsSuccess = true; return(RedirectToAction("Export")); } catch (Exception e) { _logger.Error(e); return(new HttpStatusCodeResult(400, e.Message)); } }