Exemple #1
0
        public static CSVFile LoadFromDataTable(DataTable DT, bool HasHeader = true)
        {
            CSVFile CSVF = new CSVFile();

            if (HasHeader)
            {
                CSVLine L = new CSVLine();

                foreach (DataColumn C in DT.Columns)
                {
                    L.Columns.Add(C.ColumnName);
                }
                CSVF.Lines.Add(L);
            }
            foreach (DataRow R in DT.Rows)
            {
                CSVLine L = new CSVLine();

                foreach (DataColumn C in DT.Columns)
                {
                    L.Columns.Add(R[C.ColumnName].ToString());
                }
                CSVF.Lines.Add(L);
            }
            return(CSVF);
        }
Exemple #2
0
        public static CSVFile LoadFromFileData(StreamReader ReadFile, string ColDelimiter = ",")
        {
            CSVFile CSVF = new CSVFile();

            CSVF.ColumnDelimiter = ColDelimiter;

            var parser = new CsvParser(ReadFile, new Configuration()
            {
                Delimiter = ColDelimiter
            });

            while (true)
            {
                var line = parser.Read();

                if (line == null)
                {
                    break;
                }
                else
                {
                    CSVF.Lines.Add(new CSVLine(line.ToList()));
                }
            }
            return(CSVF);
        }