public static DataTable Parse( TextReader stream, bool headers ) { DataTable table = new DataTable(); CsvStream csv = new CsvStream( stream ); string[] row = csv.GetNextRow(); if( row == null ) return null; if( headers ) { foreach( string header in row ) { if( header != null && header.Length > 0 && !table.Columns.Contains( header ) ) table.Columns.Add( header, typeof( string ) ); else table.Columns.Add( GetNextColumnHeader( table ), typeof( string ) ); } row = csv.GetNextRow(); } while( row != null ) { while( row.Length > table.Columns.Count ) table.Columns.Add( GetNextColumnHeader( table ), typeof( string ) ); table.Rows.Add( row ); row = csv.GetNextRow(); } return table; }
public static DataTable Parse(TextReader stream, bool headers) { DataTable table = new DataTable(); CsvStream csv = new CsvStream(stream); string[] row = csv.GetNextRow(); if (row == null) { return(null); } if (headers) { foreach (string header in row) { if (header != null && header.Length > 0 && !table.Columns.Contains(header)) { table.Columns.Add(header, typeof(string)); } else { table.Columns.Add(GetNextColumnHeader(table), typeof(string)); } } row = csv.GetNextRow(); } while (row != null) { while (row.Length > table.Columns.Count) { table.Columns.Add(GetNextColumnHeader(table), typeof(string)); } table.Rows.Add(row); row = csv.GetNextRow(); } return(table); }