/// <summary> /// Chuyen file tu data set qua xml /// </summary> /// <param name="file"></param> /// <param name="objMash"></param> /// <returns></returns> public static string SaveFileExcelToXml(HttpPostedFile file, List <ExportMash> objMash, out string TableName) { TableName = string.Empty; string filePath = string.Empty; if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["virtualImFolder"])) { filePath = ConfigurationManager.AppSettings["virtualImFolder"].TrimEnd('\\'); } else { filePath = HostingEnvironment.MapPath("~") + "Resources\\ImportFolder"; } //ConfigurationManager.AppSettings["importFolder"]; string fileName = string.Empty; if (string.IsNullOrEmpty(file.FileName)) { return(string.Empty); } else { fileName = file.FileName.Substring(file.FileName.LastIndexOf("\\") + 1); } string directoryName = filePath + "\\" + fileName; if (!System.IO.Directory.Exists(filePath)) { System.IO.Directory.CreateDirectory(filePath); } if (File.Exists(directoryName)) { File.Delete(directoryName); } file.SaveAs(directoryName); DataSet ds = ExcelHelper.getDataSet(directoryName, true); if (ds != null && ds.Tables.Count > 0) { ds.Locale = System.Globalization.CultureInfo.CreateSpecificCulture("en-US"); //ds.ExtendedProperties["UTCDifference"] = TimeZone.CurrentTimeZone.StandardName; foreach (ExportMash mas in objMash) { if (ds.Tables[0].Columns.Contains(mas.MashName) && mas.IsInsert) { ds.Tables[0].Columns[mas.MashName].ColumnName = mas.ColumName; } } SetUtcDateTime(ref ds); TableName = "Table1"; filePath += "\\" + System.Guid.NewGuid() + ".xml"; ds.Tables[0].TableName = TableName; // SaveDataSet(ds, filePath); ds.WriteXml(filePath); return(filePath); } return(string.Empty); }
/// <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); }