/// <summary> /// get customized datatable /// </summary> /// <param name="filePath">the source file path, contain data, txt or excel</param> /// <param name="result">template of xml that we setup with ourself</param> /// <param name="pattern">regex of the file, replace some string to the other string</param> /// <param name="replacement">replacement string</param> /// <returns>customized datatable</returns> public static DataTable GetCustomizedDataTable(string filePath, ParserEntity result, string pattern, string replacement) { DataTable dataTable = ExcelTextUtil.ReadText(filePath, result.SplitRegex, pattern, replacement); DataTable dt = GetCustomizedDataTable(result, dataTable); return(dt); }
/// <summary> /// customized datatable /// </summary> /// <param name="filePath">the source file path, contain data, txt or excel</param> /// <param name="result">template of xml that we setup with ourself</param> /// <returns>customized datatable</returns> public static DataTable GetCustomizedDataTable(string filePath, ParserEntity result) { try { DataTable dataTable = null; if (result.IsExcel) { try { dataTable = ExcelTextUtil.ReadSheet(filePath, result.SheetName); } catch (Exception ex) { try { dataTable = ExcelTextUtil.ReadFirstSheet(filePath); } catch (Exception exp) { throw new Exception("Excel 文件格式不正确,请检查!"); } } } else { dataTable = ExcelTextUtil.ReadText(filePath, result.SplitRegex); } DataTable dt = GetCustomizedDataTable(result, dataTable); return(dt); } catch (Exception e) { throw new Exception("Excel 文件格式不正确,请检查。"); } }