Exemplo n.º 1
0
        public static ColumnBasedTable CreateColumnBaseTableFromCsv(string file, Encoding enc)
        {
            var table = new ColumnBasedTable();

            using (var fs = new FileStream(file, FileMode.Open))
            {
                var          reader    = new StreamReader(fs, enc);
                int          line_id   = 0;
                string       firstline = reader.ReadLine();
                string[]     col_names = ParseCsvLine(firstline);
                int          col_count = col_names.Length;
                DataColumn[] columns   = new DataColumn[col_count];
                for (int i = 0; i < col_count; ++i)
                {
                    columns[i] = table.CreateDataColumn(col_names[i]);
                }

                line_id++;
                string line = reader.ReadLine();
                while (line != null)
                {
                    string[] cells = ParseCsvLine(line);
                    if (cells.Length != col_count)
                    {
                        throw new NotSupportedException("column count not match!");
                    }
                    for (int i = 0; i < col_count; ++i)
                    {
                        columns[i].AddData(cells[i]);
                    }

                    line_id++;
                    line = reader.ReadLine();
                }
                reader.Close();
                fs.Close();
            }
            return(table);
        }
Exemplo n.º 2
0
 internal DataColumn(ColumnBasedTable ownerTable, string name)
 {
     ColumnName  = name;
     _ownerTable = ownerTable;
 }