读写excel,C#读写Excel的海量数据并验证

为期2个月的开发,我们的项目终于上线了,我们的这个项目是属于民政行业的,建立这个项目的关键就是把所以的农户信息入库我们的系统。因为所有业务都围绕农户展开,所以我们前期的农户信息采集给项目造成了很大的困难。我们决定提供统一的EXCEL表格,让基层去采集数据,然后我们在系统中整体导入。虽然我们制定了表格模板,但是由于录信息的是不同文化层次的人,录入的数据样式各异,以至于给我们导入带来了很多的问题。“没有做不到,只有想不到”,最后我总结了问题,成功的完成了海量、复杂和经过复杂验证的数据导入。现在我把关键代码和大家分享,请大牛们能指点!
C#读写Excel的海量数据并验证读写excelC#读写Excel的海量数据并验证读写excelView Code 1 //读取服务器文件夹 2 void ExportExa(HttpContext context) 3 { 4 string[] aPath; 5 DirectoryInfo dInfo; 6 showS = new StringBuilder(); 7 if (Directory.Exists(context.Server.MapPath("temp"))) 8 { 9 aPath = Directory.GetDirectories(context.Server.MapPath("temp"));//获取文件夹的子文件夹 10 try 11 { 12 foreach (string itemPath in aPath)//循环Temp文件夹 13 { 14 dInfo = new DirectoryInfo(itemPath); 15 xName = dInfo.Name; 16 foreach (string item in Directory.GetDirectories(itemPath))//循环乡镇文件夹 17 { 18 dInfo = new DirectoryInfo(item); 19 showS.Append("\r\n"); 20 showS.Append(dInfo.Name + "---------------------------------------------------------------------------------\r\n"); 21 ProcessDirectory(context, item); 22 } 23 24 } 25 } 26 catch (Exception ex) 27 { 28 showS.Append("错误:" + ex + "\r\n"); 29 } 30 finally 31 { 32 //写入txt文件 33 using (FileStream txtFs = new FileStream(context.Server.MapPath(@"temp\" + xName + ".txt"), FileMode.Create)) 34 { 35 using (StreamWriter txtsw = new StreamWriter(txtFs, System.Text.Encoding.UTF8)) 36 { 37 txtsw.Flush(); 38 txtsw.BaseStream.Seek(0, SeekOrigin.Begin); 39 txtsw.Write(showS.ToString()); 40 txtsw.Flush(); 41 txtsw.Close(); 42 } 43 txtFs.Close(); 44 } 45 ResponseMang(context, "导入完成"); 46 //this.Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", ""); 47 } 48 } 49 }

....还有代码发布出错!!!!
Tags: 

延伸阅读

最新评论

发表评论