当前位置: 首页>>代码示例>>C#>>正文


C# CsvFileReader类代码示例

本文整理汇总了C#中CsvFileReader的典型用法代码示例。如果您正苦于以下问题:C# CsvFileReader类的具体用法?C# CsvFileReader怎么用?C# CsvFileReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CsvFileReader类属于命名空间,在下文中一共展示了CsvFileReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: showButton_Click

        private void showButton_Click(object sender, EventArgs e)
        {
            FileStream aStream = new FileStream(fileLocation, FileMode.OpenOrCreate);
            CsvFileReader aReader = new CsvFileReader(aStream);
            List<string> aPeronRecord = new List<string>();


            personListView.Items.Clear();



            while (aReader.ReadRow(aPeronRecord))
            {
                ListViewItem listViewItem = new ListViewItem(new string[]
                {
                    aPeronRecord[0],
                    aPeronRecord[1],
                    aPeronRecord[2],
                    aPeronRecord[3],
                    aPeronRecord[4]
                
                }
            );
                personListView.Items.Add(listViewItem);
            }
            aStream.Close();
        }
开发者ID:saddamhossain,项目名称:Project,代码行数:27,代码来源:Form1.cs

示例2: saveButton_Click

        private void saveButton_Click(object sender, EventArgs e)
        {
            FileStream aStreamForReading = new FileStream(fileLocation, FileMode.Open);
            CsvFileReader aReader = new CsvFileReader(aStreamForReading);
            List<string> aRecord = new List<string>();

            while (aReader.ReadRow(aRecord))
            {

                string regNo = aRecord[0];
                if (regNoTextBox.Text == regNo)
                {
                    MessageBox.Show(@"Reg no already exists");
                    aStreamForReading.Close();
                    return;
                }
            }
            aStreamForReading.Close();

            FileStream aStream = new FileStream(fileLocation, FileMode.Append);
            CsvFileWriter aWriter = new CsvFileWriter(aStream);
            List<string> aStudentRecord = new List<string>();
            aStudentRecord.Add(regNoTextBox.Text);
            aStudentRecord.Add(nameTextBox.Text);
            aWriter.WriteRow(aStudentRecord);
            aStream.Close();
        }
开发者ID:SyedArifulIslamEmon,项目名称:BasisTraining,代码行数:27,代码来源:StudentRecordKeepingUI.cs

示例3: readPlayers

 public Dictionary<string, Player> readPlayers()
 {
     Dictionary<string, Player> listPlayers = new Dictionary<string, Player>();
     using (CsvFileReader reader = new CsvFileReader(file))
     {
         CsvRow row = new CsvRow();
         while (reader.ReadRow(row))
         {
             listPlayers.Add(row[Constants.FName], new Player(row[Constants.FName], boolFromString(row[Constants.FBoolTerran]),
                 boolFromString(row[Constants.FBoolZerg]), boolFromString(row[Constants.FBoolProtoss]), boolFromString(row[Constants.FBoolRandom])));
             Player temp = listPlayers[row[Constants.FName]];
             int.TryParse(row[Constants.FVictoryTerran], out temp.Victory[Constants.Terran]);
             int.TryParse(row[Constants.FVictoryZerg], out temp.Victory[Constants.Zerg]);
             int.TryParse(row[Constants.FVictoryProtoss], out temp.Victory[Constants.Protoss]);
             int.TryParse(row[Constants.FVictoryRandom], out temp.Victory[Constants.Random]);
             int.TryParse(row[Constants.FDefeatTerran], out temp.Defeat[Constants.Terran]);
             int.TryParse(row[Constants.FDefeatZerg], out temp.Defeat[Constants.Zerg]);
             int.TryParse(row[Constants.FDefeatProtoss], out temp.Defeat[Constants.Protoss]);
             int.TryParse(row[Constants.FDefeatRandom], out temp.Defeat[Constants.Random]);
             int.TryParse(row[Constants.FEloTerran], out temp.Elo[Constants.Terran]);
             int.TryParse(row[Constants.FEloZerg], out temp.Elo[Constants.Zerg]);
             int.TryParse(row[Constants.FEloProtoss], out temp.Elo[Constants.Protoss]);
             int.TryParse(row[Constants.FEloRandom], out temp.Elo[Constants.Random]);
         }
     }
     return listPlayers;
 }
开发者ID:dosimont,项目名称:sc2_matchmaker,代码行数:27,代码来源:PlayerReader.cs

示例4: CsvLoadTripRoutes

        public static void CsvLoadTripRoutes(string filename, bool lngFirst)
        {
            // load trip routes
            Dictionary<string, LinkedList<Waypoint>> routes = new Dictionary<string, LinkedList<Waypoint>>();
            using (CsvFileReader reader = new CsvFileReader(filename))
            {
                CsvRow row = new CsvRow();
                while (reader.ReadRow(row, ','))
                {
                    string routeID = row[0];
                    double distance = 0;
                    double lat = Convert.ToDouble(lngFirst ? row[2] : row[1]);
                    double lng = Convert.ToDouble(lngFirst ? row[1] : row[2]);
                    if (routes.ContainsKey(routeID))
                        distance = routes[routeID].First.Value.GetDistance(new Location(lat, lng, "null"));
                    Waypoint waypoint = new Waypoint(lat, lng, TimeSpan.Parse(row[3]), distance, row[4].Replace("\"", ""));

                    // Scenario #1
                    if (!routes.ContainsKey(routeID))
                        routes[routeID] = new LinkedList<Waypoint>();
                    routes[routeID].AddLast(waypoint);

                }
            }
            foreach (LinkedList<Waypoint> w in routes.Values)
            {
                Route r = new Route(w.ToArray());
                string key = Route.GetKey(r.start, r.end);
                MapTools.routes.Add(key, r);
            }
        }
开发者ID:TripThru,项目名称:Gateway,代码行数:31,代码来源:1397817436$MapTools.cs

示例5: EventPointsReader

        public EventPointsReader(String filePath, Boolean skipHeader)
        {
            this.EventPoints = new List<EventPoint>();

            CsvFileReader reader = new CsvFileReader(filePath);

            Boolean headerSkipped = false;

            while (true)
            {
                CsvRow row = new CsvRow();
                if (reader.ReadRow(row))
                {
                    if ((skipHeader && headerSkipped) ||
                        !skipHeader)
                    {
                        EventPoint ep = new EventPoint();
                        ep.LongCode = row[0];
                        ep.ShortCode = row[1];
                        ep.DateTimeFrom = DateTime.ParseExact(row[2], "yyyy-MM-dd HH:mm:ss.fff", null);
                        ep.DateTimeTo = DateTime.ParseExact(row[3], "yyyy-MM-dd HH:mm:ss.fff", null);
                        ep.RangeMax = Convert.ToDouble(row[4]);
                        ep.RangeMin = Convert.ToDouble(row[5]);

                        this.EventPoints.Add(ep);
                    }
                    headerSkipped = true;
                }
                else
                {
                    break;
                }
            }
        }
开发者ID:HongSeokHwan,项目名称:legacy,代码行数:34,代码来源:EventPointsReader.cs

示例6: loadSNPSPToolStripMenuItem_Click

        private void loadSNPSPToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _openFileDialog.FileName = "SNPCC.csv";
            _openFileDialog.Filter = "csv files (*.csv)|*.csv";
            _openFileDialog.DefaultExt = "txt";
            _openFileDialog.FilterIndex = 2;
            _openFileDialog.AddExtension = true;
            if (_openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string fileName = _openFileDialog.FileName;
                CsvFileReader csv = new CsvFileReader(fileName);
                char[] _separators = new char[] { '\n', '"', ',' };
                CsvRow row = new CsvRow();
                bool entering = true;
                while (entering == true)
                {
                    entering = csv.ReadRow(row);
                    staters.Add(new Stater(row[1], row[0]));
                    char[] bar = row[2].ToCharArray();
                    string bs = Convert.ToString(bar[0]) + Convert.ToString(bar[1]) + Convert.ToString(bar[2]) + Convert.ToString(bar[3]);
                    staters[staters.Count - 1].Barcode = Convert.ToInt32(bs);
                    staters[staters.Count - 1].City = row[3];
                    staters[staters.Count - 1].County = row[4];
                }

                csv.Close();
                staters.RemoveAt(staters.Count - 1);
                List<Stater> testing = staters;
            }
        }
开发者ID:ThaddeusT,项目名称:StaterPhotoSuite,代码行数:30,代码来源:Form1.cs

示例7: btnShow_Click

        private void btnShow_Click(object sender, EventArgs e)
        {
            FileStream aStream = new FileStream(fileLocation, FileMode.Open);
            CsvFileReader aReader = new CsvFileReader(aStream);

            List<string> outList = new List<string>();

            lstViewOut.SelectedIndices[0];
        }
开发者ID:SyedArifulIslamEmon,项目名称:BasisTraining,代码行数:9,代码来源:AddressBookUI.cs

示例8: TestCsvFileReadUsingSoundex

 public void TestCsvFileReadUsingSoundex()
 {
     var reader = new CsvFileReader();
     reader.RecordBuilder = new SinglePropertyRecordBuilder(@"Name");
     reader.ValueFactory = new SoundexValueFactory(5);
     var dataset = reader.ReadFile(new FileInfo(@"data/ReferenceDataset1.csv"), true, ',');
     Assert.AreEqual(1, dataset.Records.Count, @"Record count is wrong!");
     foreach (var record in dataset.Records)
     {
         Assert.AreEqual(1, record.Properties.Count, @"Property count is wrong!");
         Assert.AreEqual(@"A4253", record.Properties[@"Name"], @"Soundex code is wrong!");
     }
 }
开发者ID:gisfromscratch,项目名称:geocoding-samples,代码行数:13,代码来源:CsvFileReaderTestSuite.cs

示例9: showButton_Click

        private void showButton_Click(object sender, EventArgs e)
        {
            FileStream aStream = new FileStream(fileLocation, FileMode.Open);
            CsvFileReader aReader = new CsvFileReader(aStream);
            List<string> aStudentRecord = new List<string>();

            studentListBox.Items.Clear();

            while (aReader.ReadRow(aStudentRecord))
            {
                string regNo = aStudentRecord[0];
                string name = aStudentRecord[1];
                studentListBox.Items.Add(regNo + " " + name);
            }
            aStream.Close();
        }
开发者ID:SyedArifulIslamEmon,项目名称:BasisTraining,代码行数:16,代码来源:StudentRecordKeepingUI.cs

示例10: LoadRecords

 private static IList<Record> LoadRecords(string fileContent)
 {
     const string filepath = "filepath";
     var mocks = new MockRepository(MockBehavior.Strict);
     Mock<IFileSystem> fileSystemMock = mocks.Create<IFileSystem>();
     fileSystemMock.Setup(it => it.OpenFileForRead(filepath))
         .Returns(new MemoryStream(Encoding.ASCII.GetBytes(fileContent)));
     IFileSystem fileSystem = fileSystemMock.Object;
     var reader = new CsvFileReader(fileSystem);
     reader.Open(filepath);
     IList<Record> records = new List<Record>();
     while (reader.MoveNext()) {
         records.Add(reader.CurrentRecord);
     }
     return records;
 }
开发者ID:rgavrilov,项目名称:Sogeti,代码行数:16,代码来源:CsvFileReaderTest.cs

示例11: btnEntryShow_Click

        private void btnEntryShow_Click(object sender, EventArgs e)
        {
            FileStream aStream = new FileStream(fileLocation, FileMode.Open);
            CsvFileReader aReader = new CsvFileReader(aStream);

            List<string> record = new List<string>();

            while (aReader.ReadRow(record))
            {
                string bill = record[0];
                double aBill = Convert.ToDouble(bill);
                aBill += aBill;
                txtBoxTotalExpns.Text = aBill.ToString();
            }
            aStream.Close();
        }
开发者ID:SyedArifulIslamEmon,项目名称:BasisTraining,代码行数:16,代码来源:DailyEntryUI.cs

示例12: saveButton_Click

        private void saveButton_Click(object sender, EventArgs e)
        {

            FileStream aStream = new FileStream(fileLocation, FileMode.OpenOrCreate);
           
            CsvFileReader aReader = new CsvFileReader(aStream);
            List<string> aPeronRecord = new List<string>();


            //personListView.Items.Clear();



            while (aReader.ReadRow(aPeronRecord))
            {
                if (aPeronRecord[2] == personalCnTextBox.Text)
                {
                    MessageBox.Show("conflict");

                    aStream.Close();
                    return;
                }
            }
            aStream.Close();



            FileStream aStream2 = new FileStream(fileLocation, FileMode.Append);
            CsvFileWriter aWriter = new CsvFileWriter(aStream2);
            List<string> aPersonRecod = new List<string>();

            aPersonRecod.Add(nameTextBox.Text);
            aPersonRecod.Add(emailTextBox.Text);
            aPersonRecod.Add(personalCnTextBox.Text);
            aPersonRecod.Add(homeCnTextBox.Text);
            aPersonRecod.Add(homeAddressTextBox.Text);

            aWriter.WriteRow(aPersonRecod);

            aStream2.Close();

            
                    


        }
开发者ID:saddamhossain,项目名称:Project,代码行数:46,代码来源:Form1.cs

示例13: InMemoryFileWithNoHeader

        private static void InMemoryFileWithNoHeader()
        {
            Console.WriteLine("Test In Memory File With No Header");
            var csvDefinition = new CsvDefinition
                {
                    Header = "ClientId|FirstName|LastName|Occupation|City",
                    FieldSeparator = '|'
                };

            var csvWithNoHeader = new CsvFileReader<Client>(
                new StringReader("1|Pascal|Ganaye|CodeMonkey|Macon\r" +
                                 "2|Mick|Jagger|Singer|Dartford"), csvDefinition
                );
            foreach (var c in csvWithNoHeader)
                Console.WriteLine(string.Format("Client #{0}: {1} ({2} in {3})",
                                                c.ClientId,
                                                c.FirstName + (string.IsNullOrEmpty(c.MiddleName) ? " " : " " + c.MiddleName + " ") + c.LastName,
                                                c.Occupation,
                                                c.City));
        }
开发者ID:haihoi2,项目名称:KeywordSimilarity,代码行数:20,代码来源:SampleProgram.cs

示例14: TestWritingCsvRecords

        public void TestWritingCsvRecords()
        {
            var reader = new CsvFileReader();
            var dataset = reader.ReadFile(new FileInfo(@"data/ReferenceDataset1.csv"), true, ',');
            Assert.AreEqual(1, dataset.Records.Count, @"Record count is wrong!");

            var record = Enumerable.First<IReferenceRecord>(dataset.Records);
            const string Key = @"Name";

            var indexWriter = new IndexFileWriter();
            var indexFile = new FileInfo(Path.GetTempFileName());
            indexWriter.WriteFile(indexFile, dataset.Records);

            var indexReader = new IndexFileReader();
            var writtenRecords = indexReader.ReadFile(indexFile);
            var writtenRecord = Enumerable.First<IReferenceRecord>(writtenRecords);
            Assert.AreEqual(record.Properties.Count, writtenRecord.Properties.Count, @"The number of properties do not match!");
            Assert.IsTrue(writtenRecord.Properties.ContainsKey(@"Name"), @"There is no property having a key equal to 'Name'!");
            Assert.AreEqual(record.Properties[Key], writtenRecord.Properties[Key], @"The property values do not match!");
        }
开发者ID:gisfromscratch,项目名称:geocoding-samples,代码行数:20,代码来源:IndexFileWriterTestSuite.cs

示例15: CreateInsertQueries

        public List<string> CreateInsertQueries(string fileName)
        {
            List<string> queries = new List<string>();

            CsvFileReader reader = new CsvFileReader(fileName);

            bool firstRowRead = false;
            while (true)
            {
                if (reader.EndOfStream)
                {
                    break;
                }

                CsvRow row = new CsvRow();
                reader.ReadRow(row);

                if (!firstRowRead)
                {
                    firstRowRead = true;
                    continue;
                }

                if (row[4].CompareTo("USD") == 0)
                {
                    continue;
                }

                string ticker = String.Format("USD{0} Curncy", row[4]);
                string desc = String.Format("{0} / 1 usd currency", row[0]);
                string queryDelete = String.Format(
                    "delete from product_list where ticker = '{0}'", ticker);
                string queryInsert = String.Format(
                    "insert into product_list values ('{0}', 'USD', '{1}', 0, 0, 'Index')",
                    ticker, desc);
                queries.Add(queryDelete);
                queries.Add(queryInsert);
            }

            return queries;
        }
开发者ID:HongSeokHwan,项目名称:legacy,代码行数:41,代码来源:CurncyTickerQueryGenerator.cs


注:本文中的CsvFileReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。