public static CSVResult Load(string strCSVPath) { CSVResult result = CSVResult.GetInstance(); _result = result; if (!File.Exists(strCSVPath)) { using(System.IO.File.Create(strCSVPath)) { Console.WriteLine("Create File."); } using (var writer = new CsvWriter(new StreamWriter(strCSVPath))) { foreach (var temp in _result.result) { writer.WriteField(temp.strNameFromCustom); } writer.NextRecord(); // for inner debug foreach (var temp in _result.result) { writer.WriteField(temp.strNameInCode); } writer.NextRecord(); foreach (var temp in _result.result) { if (temp.strOCRResult != null) { if (temp.strOCRResult.Equals("")) { writer.WriteField(""); } else { writer.WriteField(temp.strOCRResult); } } else { writer.WriteField(temp.strOCRResult); } } writer.NextRecord(); } return result; } using (var reader = new CsvReader(new StreamReader(strCSVPath))) { System.IO.FileInfo file = new System.IO.FileInfo(strCSVPath); if (file.Length == 0)//判断一下大小,要是为零就不读了 { return result; } while (reader.Read()) { foreach (var temp in result.result) { try { temp.strOCRResult = reader.GetField(temp.strNameFromCustom); } catch (System.Exception ex) { temp.strOCRResult = ""; } } } } return result; }
public CSVEngine(string strImageName, string strFormType, CSVResult result) { _result = result; foreach (var temp in result.result) { if (temp.strNameFromCustom.Equals("DocFileName")) { temp.strOCRResult = strImageName; } if (temp.strNameFromCustom.Equals("DocumentType")) { temp.strOCRResult = strFormType; } } }
public CSVEngine(CSVResult result) { _result = result; }
public static CSVResult GetInstance() { if (instance == null) { instance = new CSVResult(); } return instance; }