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 DownloadExcelFromJsonfn(string fields, string data) { try { DataSet DsData = new DataSet(); DataTable DtData = SharedServices.JsonToDT(data); JArray ArryFields = JArray.Parse(fields); for (int i = 0; i < ArryFields.Count; i++) { DtData.Columns[i].ColumnName = ArryFields[i].ToString(); } for (int i = 0; i < ArryFields.Count; i++) { var name = ArryFields[i].ToString(); if (name.IndexOf(",hide") > -1) { DtData.Columns.Remove(name); } } DsData.Tables.Add(table: DtData); DownloadExcelModel excelModel = new DownloadExcelModel { DataSouece = DsData }; return(DownloadExcelFromDBfn(excelModel)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
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")); }