//********************************************************************************************* public static DataTable TXT_To_DataTable(string dirTXT) { StreamReader objReader = new StreamReader(dirTXT, Encoding.Default); DataTable dt = new DataTable(); string strline; string[] aryline; bool blnFlag = false; while ((strline = objReader.ReadLine()) != null) { aryline = strline.Split(new char[] { ' ' }, StringSplitOptions.None); if (blnFlag == false) { DataColumn mydc = null; foreach (string str in aryline) { mydc = new DataColumn(str); dt.Columns.Add(mydc); } blnFlag = true; } else { dt.Rows.Add(aryline); } } objReader.Close(); return dt; } /// <summary> /// 以Tab键为间隔,以Tab键表示空值 /// </summary> /// <param name="dirTXT"></param> /// <returns></returns> public static DataTable TXT_To_DataTable2(string dirTXT) { StreamReader objReader = new StreamReader(dirTXT, Encoding.Default); DataTable dt = new DataTable(); string strline; string[] aryline; bool blnFlag = false; while ((strline = objReader.ReadLine()) != null) { aryline = strline.Split(new char[] { ' ' }, StringSplitOptions.None); if (blnFlag == false) { foreach (string str in aryline) { if (!string.IsNullOrEmpty(str)) { DataColumn mydc = new DataColumn(str); dt.Columns.Add(mydc); } } blnFlag = true; } else { if (aryline.Count() != dt.Columns.Count) { strline = Lines_To_Replace(strline); aryline = strline.Split(new char[] { ' ' }, StringSplitOptions.None); } dt.Rows.Add(aryline); } } objReader.Close(); return dt; } public static string Lines_To_Replace(string lines) { for (int i = 0; i < lines.Length; i++) { if (i != lines.Length - 1 && i > 0 && lines.Substring(i - 1, 1) == " " && lines.Substring(i, 1) == " " && lines.Substring(i + 1, 1) == " ") { //lines.Substring(i, 1) = " "; lines = lines.Substring(0, i) + "