Ejemplo n.º 1
0
        public bool Read(string file, FileShare fs = FileShare.None)
        {
            Rows = new List <Row>();

            if (!File.Exists(file))
            {
                return(false);
            }

            try
            {
                using (Stream s = File.Open(file, FileMode.Open, FileAccess.Read, fs))
                {
                    using (StreamReader sr = new StreamReader(s))
                    {
                        CSVRead csv = new CSVRead(sr);

                        CSVRead.State st;

                        Row l = new Row();

                        string str;
                        while ((st = csv.Next(out str)) != CSVRead.State.EOF)
                        {
                            l.Cells.Add(str);

                            if (st == CSVRead.State.ItemEOL)
                            {
                                Rows.Add(l);
                                l = new Row();
                            }
                        }

                        if (l.Cells.Count > 0)
                        {
                            Rows.Add(l);
                        }

                        return(true);
                    }
                }
            }
            catch
            {
                return(false);
            }
        }