/// <summary> /// thực hiện xuất file theo store /// </summary> /// <param name="store">Tên store lấy Data</param> /// <param name="SheetName">Tên Sheet trên file Excel</param> /// <param name="fileNameExport">Tên file xuất ra</param> /// <param name="type"> /// các dạng file có thể xuất /// [StringValue("XLS")] /// Excel_97_2003 = 1, /// Excel_2007 = 2, /// Comma_Separated_Values = 5, /// OpenOffice_Spreadsheet = 6, /// Hyper_Text_Markup_Language = 7, /// </param> /// <param name="FileMashName">Tên file Mash /// FileMash: là file map giưa các columnName và header hiển thị trên file Excel /// </param> /// <param name="paras"> /// Danh sách parramter chuyền vào cho store /// </param> public static void Flush(string store, string SheetName, string fileNameExport, FileType type, string FileMashName, params object[] paras) { string FileMashPath = ExcelHelper.GetFileMashFullPath(FileMashName); fileNameExport += "." + type.GetStringValue(); DataSet ds = new DataSet(); SqlHelper.ExecuteDataset(ds, store, paras); List <ExportMash> lstMash = ListMash(FileMashPath); List <DataColumn> clRemove = new List <DataColumn>(); bool CheckColumn; foreach (DataColumn item in ds.Tables[0].Columns) { CheckColumn = false; foreach (ExportMash Maitem in lstMash) { if (item.ColumnName == Maitem.ColumName) { item.ColumnName = Maitem.MashName.Trim(); CheckColumn = true; break; } } if (!CheckColumn) { clRemove.Add(item); } } foreach (DataColumn dr in clRemove) { ds.Tables[0].Columns.Remove(dr); } ExcelHelper.ToExcel(ds, fileNameExport, SheetName, type); }
public static void Flush(DataSet ds, string SheetName, string fileNameExport, string Filetype, string FileMashName) { FileType type = GetFileType(Filetype.ToUpper()); string FileMashPath = ExcelHelper.GetFileMashFullPath(FileMashName); fileNameExport += "." + type.GetStringValue(); List <ExportMash> lstMash = ListMash(FileMashPath); DataTable tmp = ds.Tables[0].Copy(); ds.Tables[0].Constraints.Clear(); if (lstMash.Count > 0) { foreach (DataColumn item in tmp.Columns) { IEnumerable <ExportMash> results = ( from obj in lstMash where obj.ColumName == item.ColumnName select obj); if (results.Count <ExportMash>() <= 0) { ds.Tables[0].Columns[item.ColumnName].AllowDBNull = true; ds.Tables[0].Columns.Remove(item.ColumnName); } } foreach (DataColumn item in ds.Tables[0].Columns) { IEnumerable <ExportMash> results = ( from obj in lstMash where obj.ColumName == item.ColumnName select obj); if (results.Count <ExportMash>() > 0) { item.ColumnName = results.Single().MashName.Trim(); } } } ExcelHelper.ToExcel(ds, fileNameExport, SheetName, type); }
/// <summary> /// Xuất ra file theo dataSet /// </summary> /// <param name="ds">Data set</param> /// <param name="fileName">Tên file xuất ra</param> /// <param name="type"> /// các dạng file có thể xuất /// [StringValue("XLS")] /// Excel_97_2003 = 1, /// Excel_2007 = 2, /// Comma_Separated_Values = 5, /// OpenOffice_Spreadsheet = 6, /// Hyper_Text_Markup_Language = 7, /// </param> public static void Flush(DataSet ds, string fileName, string SheetName, FileType type) { fileName += "." + type.GetStringValue(); ExcelHelper.ToExcel(ds, fileName, SheetName, type); }