public void AutoRemoveQuotes() { CsvEngine eng = new CsvEngine(new CsvOptions("YourClass", ',', 2, 0)); DataTable dt = eng.ReadFileAsDT(TestCommon.GetPath("Good", "QuoteMode1.txt")); Assert.AreEqual("VINET", dt.Rows[0][1]); }
/// <summary> /// Reads a CSV File and return their contents as /// DataTable /// </summary> /// <param name="filename">The file to read.</param> /// <param name="options">The options used to create the record mapping class.</param> /// <returns>The contents of the file as a DataTable</returns> public static DataTable CsvToDataTable(string filename, CsvOptions options) { var engine = new CsvEngine(options); #pragma warning disable 618 return(engine.ReadFileAsDT(filename)); #pragma warning restore 618 }
public void DualEngine() { string file = TestCommon.GetPath("Good", "RealCsvVerticalBar2.txt"); string classname = "CustomerVerticalBar"; char delimiter = '|'; CsvEngine engine = new CsvEngine(classname, delimiter, file); CsvEngine engine2 = new CsvEngine(classname, delimiter, file); }
public void ReadFileHeader1() { string file = TestCommon.GetPath("Good", "RealCsvComma1.txt"); string classname = "CustomerComma"; char delimiter = ','; CsvOptions options = new CsvOptions(classname, delimiter, file); options.HeaderLines = 0; CsvEngine engine = new CsvEngine(options); Assert.AreEqual(classname, engine.RecordType.Name); DataTable dt = engine.ReadFileAsDT(file); Assert.AreEqual(21, dt.Rows.Count); Assert.AreEqual(21, engine.TotalRecords); Assert.AreEqual(0, engine.ErrorManager.ErrorCount); Assert.AreEqual("Field_0", dt.Columns[0].ColumnName); }
/// <summary> /// Reads a CSV File and return their contents as /// DataTable /// </summary> /// <param name="filename">The file to read.</param> /// <param name="options">The options used to create the record mapping class.</param> /// <returns>The contents of the file as a DataTable</returns> public static DataTable CsvToDataTable(string filename, CsvOptions options) { var engine = new CsvEngine(options); return(engine.ReadFileAsDT(filename)); }
public List<BaseballGame> GetGames() { FileInfo[] files = new DirectoryInfo(Global.FILES_DIR).GetFiles(); var people = GetPeople(); var teams = GetTeams(); List<BaseballGame> games = new List<BaseballGame>(); int idCounter = 0; foreach (var file in files) { var csvTable = FileHelpers.CsvEngine.CsvToDataTable(file.FullName, new CsvOptions("Test", ',', 161)); CsvEngine engine = new CsvEngine(new CsvOptions("BaseballGame", ',', 161)); foreach (DataRow row in csvTable.Rows) { BaseballGame game = new BaseballGame(); game.Id = idCounter.ToString(); string home = null; teams.TryGetValue(row[6].ToString().Replace("\"", "") + row[7].ToString().Replace("\"", ""), out home); game.HomeTeam = home; string visitor = null; teams.TryGetValue(row[3].ToString().Replace("\"", "") + row[4].ToString(), out visitor); game.DocType = DocType.BaseballGame; game.VisitingTeam = visitor; game.DayOfTheWeek = row[2].ToString().Replace("\"", ""); game.DateRaw = row[0].ToString().Replace("\"", ""); game.Date = DateTime.ParseExact(game.DateRaw, "yyyyMMdd", null); game.Year = game.Date.Year; game.HomeTeamScore = Int32.Parse(row[10].ToString()); game.VisitingTeamScore = Int32.Parse(row[9].ToString()); game.WinningPitcher = row[94].ToString(); if (game.WinningPitcher == String.Empty) game.WinningPitcher = "Unknown"; else game.PitchersInvolved.Add(game.WinningPitcher); // losing pitcher row - row 96 game.LosingPitcher = row[96].ToString(); if (game.LosingPitcher == String.Empty) game.LosingPitcher = "Unknown"; else game.PitchersInvolved.Add(game.LosingPitcher); string dayOrNight = row[12].ToString(); if (dayOrNight == "D") game.DayOrNight = "Day"; else if (dayOrNight == "N") game.DayOrNight = "Night"; else game.DayOrNight = "Unknown"; string gameLength = row[18].ToString(); if (gameLength != String.Empty) game.LengthOfGame = Int32.Parse(gameLength); string homeUmp = null; people.TryGetValue(row[77].ToString(), out homeUmp); game.HomePlateUmpireName = homeUmp; game.Winner = (game.HomeTeamScore > game.VisitingTeamScore) ? WinningLocation.Home : WinningLocation.Visitor; if (!string.IsNullOrEmpty(game.HomeTeam)) game.TeamsInvolved.Add(game.HomeTeam); if (!string.IsNullOrEmpty(game.VisitingTeam)) game.TeamsInvolved.Add(game.VisitingTeam); games.Add(game); idCounter++; } } return games; }
public Dictionary<string, string> GetTeams() { Dictionary<string, string> teams = new Dictionary<string, string>(); var csvTable = FileHelpers.CsvEngine.CsvToDataTable(Global.TEAM_FILE, new CsvOptions("Test", ',', 5)); CsvEngine engine = new CsvEngine(new CsvOptions("Team", ',', 161)); foreach (DataRow row in csvTable.Rows) { teams.Add(row[0].ToString().Replace("\"", "") + row[1].ToString().Replace("\"", ""), row[2].ToString() + " " + row[3].ToString()); } return teams; }
/// <summary>Reads a Csv File and return their contents as DataTable</summary> /// <param name="filename">The file to read.</param> /// <param name="options">The options used to create the record mapping class.</param> /// <returns>The contents of the file as a DataTable</returns> public static DataTable CsvToDataTable(string filename, CsvOptions options) { return(CsvEngine.CsvToDataTable(filename, options)); }
/// <summary>Reads a Csv File and return their contents as DataTable</summary> /// <param name="classname">The name of the record class</param> /// <param name="delimiter">The delimiter for each field</param> /// <param name="filename">The file to read.</param> /// <param name="hasHeader">Indicates if the file contains a header with the field names.</param> /// <returns>The contents of the file as a DataTable</returns> public static DataTable CsvToDataTable(string filename, string classname, char delimiter, bool hasHeader) { return(CsvEngine.CsvToDataTable(filename, classname, delimiter, hasHeader)); }
/// <summary> /// Reads a CSV File and return their contents as DataTable (The file /// must have the field names in the first row) /// </summary> /// <param name="delimiter">The delimiter for each field</param> /// <param name="filename">The file to read.</param> /// <returns>The contents of the file as a DataTable</returns> public static DataTable CsvToDataTable(string filename, char delimiter) { return(CsvEngine.CsvToDataTable(filename, delimiter)); }
/// <summary> /// Simply dumps the DataTable contents to a delimited file. Only /// allows to set the delimiter. /// </summary> /// <param name="dt">The source Data Table</param> /// <param name="filename">The destination file.</param> /// <param name="options">The options used to write the file</param> public static void DataTableToCsv(DataTable dt, string filename, CsvOptions options) { CsvEngine.DataTableToCsv(dt, filename, options); }
/// <summary>Simply dumps the DataTable contents to a delimited file. Only allows to set the delimiter.</summary> /// <param name="dt">The source Data Table</param> /// <param name="filename">The destination file.</param> /// <param name="delimiter">The delimiter used to write the file</param> public static void DataTableToCsv(DataTable dt, string filename, char delimiter) { CsvEngine.DataTableToCsv(dt, filename, new CsvOptions("Tempo", delimiter, dt.Columns.Count)); }
/// <summary> /// Simply dumps the DataTable contents to a delimited file using a ',' /// as delimiter. /// </summary> /// <param name="dt">The source Data Table</param> /// <param name="filename">The destination file.</param> public static void DataTableToCsv(DataTable dt, string filename) { CsvEngine.DataTableToCsv(dt, filename); }
/// <summary> /// Reads a CSV File and return their contents as /// DataTable /// </summary> /// <param name="filename">The file to read.</param> /// <param name="options">The options used to create the record mapping class.</param> /// <returns>The contents of the file as a DataTable</returns> public static DataTable CsvToDataTable(string filename, CsvOptions options) { CsvEngine engine = new CsvEngine(options); return engine.ReadFileAsDT(filename); }
private void RunTest(string file, char delimiter, char delimiterHdr, string classname) { CsvOptions options = new CsvOptions(classname, delimiter, file); options.HeaderDelimiter = delimiterHdr; CsvEngine engine = new CsvEngine(options); Assert.AreEqual(classname, engine.RecordType.Name); DataTable dt = engine.ReadFileAsDT(file); Assert.AreEqual(20, dt.Rows.Count); Assert.AreEqual(20, engine.TotalRecords); Assert.AreEqual(0, engine.ErrorManager.ErrorCount); Assert.AreEqual("CustomerID", dt.Columns[0].ColumnName); }