public IActionResult DownloadExcelFromDBfn(DownloadExcelModel model) { try { DataSet ds = null; if (model.DataSouece != null) { ds = model.DataSouece; } // else ds = SharedServices.CallSP(conn, SharedServices.JsonToSPparams(model.Source_SP)); if (ds.Tables.Count == 0) { ds.Tables.Add(); ds.Tables[0].Columns.Add("-- ไม่พบข้อมูล-- "); } MemoryStream stream = SharedServices.ExcelStreaming( source: ds, SheetName: model.Excelsheetsname, Template: model.Template, LastRowIsSummary: model.LastRowIsSummary); return(File(stream, "application/vnd.ms-excel", model.ExcelName + ".xlsx")); } catch { return(BadRequest()); } }
public IActionResult DownloadCommRate([FromQuery] bool IsTemplate) { DownloadExcelModel model = new DownloadExcelModel(); List <P> parameters = new List <P> { new P { Key = "IsTemplate", Value = IsTemplate } }; DataSet source = dbServices.SpCaller(name: "dbo.PB_CommRatesDownload", parameters: parameters); model.DataSouece = source; model.ExcelName = IsTemplate ? "CommRate Template" : "CommRate Data " + DateTime.Today.ToString("dd-MM-yyyy");; MemoryStream stream = SharedServices.ExcelStreaming( source: source, SheetName: model.Excelsheetsname, Template: model.Template, LastRowIsSummary: model.LastRowIsSummary ); return(File(stream, ContentTypes.excel, model.ExcelName + ".xlsx")); }