Esempio n. 1
0
        public void LoadCsvFile(string fileName)
        {
            //对数据的有效性进行验证

            if (fileName == null)
            {
                throw new Exception("请指定要载入的CSV文件名");
            }
            else if (!File.Exists(fileName))
            {
                throw new Exception("指定的CSV文件不存在");
            }

            StreamReader sr = new StreamReader(fileName);

            _datas.Clear();
            _formObj = null;

            string csvDataLine;

            csvDataLine = "";
            while (true)
            {
                string fileDataLine;

                fileDataLine = sr.ReadLine();
                if (fileDataLine == null)
                {
                    break;
                }
                if (csvDataLine == "")
                {
                    csvDataLine = fileDataLine;
                }
                else
                {
                    csvDataLine += "/r/n" + fileDataLine;//GetDeleteQuotaDataLine(fileDataLine);
                }
                //如果包含偶数个引号,说明该行数据中出现回车符或包含逗号
                if (!IfOddQuota(csvDataLine))
                {
                    //  Debug.WriteLine(csvDataLine);
                    var linedatas = csvDataLine.Split(',');
                    _datas.Add(linedatas);
                    csvDataLine = "";
                }
            }
            sr.Close();
            //数据行出现奇数个引号
            if (csvDataLine.Length > 0)
            {
                MessageBox.Show("CSV文件的格式有错误");
                _datas.Clear();
                throw new Exception("CSV文件的格式有错误");
            }

            //BuildObjData(fileName.Replace(".csv", ".obj"));
        }
Esempio n. 2
0
 public void SetFormOBJ(CSVToObj obj)
 {
     _formObj = obj;
 }