导入CSV格式文件方法
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
/// <summary> /// 导入CSV格式文件 /// </summary> /// <param name="filePath">文件地址</param> /// <returns></returns> protected DataTable GetFlowData(string filePath) { string strline; string[] aryline; bool blnFlag = true; DataTable dt = new DataTable(); StreamReader mysr = new StreamReader(filePath, System.Text.Encoding.Default); try { int ColCount = 0; while ((strline = mysr.ReadLine()) != null) { aryline = strline.Split(new char[] { ',' }); if (blnFlag) { blnFlag = false; ColCount = aryline.Length; for (int i = 0; i < aryline.Length; i++) { dt.Columns.Add(aryline[i]); } continue; } DataRow dr = dt.NewRow(); for (int i = 0; i < ColCount; i++) { dr[i] = aryline[i]; } dt.Rows.Add(dr); } } catch (Exception ex) { throw ex; } finally { mysr.Close(); mysr.Dispose(); } return dt; }