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


C# CsvConfiguration类代码示例

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


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

示例1: CanQuoteAllFields

        public void CanQuoteAllFields()
        {
            var sb = new StringBuilder();
            var cfg = new CsvConfiguration
            {
                QuoteAllFields = true,
                Quote = '\'',
                Delimiter = ';',
                Escape = '"',
                TrimValues = true,
                SupportsMultiline = true
            };

            using (var writer = new CsvWriter(new StringWriter(sb), cfg))
            {
                writer.WriteFields(new string[]
                {
                    "1234",
                    " abc ",
                    " def",
                    "ghi ",
                    "jk\rl\nmno",
                    "pqrs"
                });

                writer.NextRow();
            }

            string expected = "'1234';'abc';'def';'ghi';'jk\rl\nmno';'pqrs'" + "\r\n";

            Assert.AreEqual(expected, sb.ToString());
        }
开发者ID:toannguyen241994,项目名称:SmartStoreNET,代码行数:32,代码来源:CsvWriterTests.cs

示例2: CsvImporterDataSnapshot

		public CsvImporterDataSnapshot() {
			this.PathCsv = "C:\\";
			this.FieldSetupCurrentName = "Default";
			this.FieldSetupsByName = new Dictionary<string, FieldSetup>();
			this.FieldSetupsByName.Add(this.FieldSetupCurrentName, new FieldSetup(this.FieldSetupCurrentName));
			
			this.CsvConfiguration = new CsvConfiguration();
			this.CsvConfiguration.Delimiter = ";";
			this.CsvConfiguration.AllowComments = true;
			this.CsvConfiguration.TrimFields = true;
			
			this.CsvFieldTypeFormatsAvailable = new Dictionary<string, List<string>>();
			this.CsvFieldTypeFormatsAvailable.Add("Open,High,Low,Close,Volume", new List<string>() {"#,###.##", "#.###,##"});
			
			//http://www.csharp-examples.net/string-format-datetime/ http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx http://msdn.microsoft.com/en-us/library/az4se3k1.aspx
			this.CsvFieldTypeFormatsAvailable.Add("Date", new List<string>() {CsvTypeParser.FORMAT_TRY_ALL,
				"d", "D", "yyyyMMdd", "yyyy-MM-dd", "yyyy-MMM-dd",
				"d/M/yyyy", "dd/MM/yyyy", "dd/MM/yy",
				"MM-dd-yy"});
			this.CsvFieldTypeFormatsAvailable["Date"].Sort();

			this.CsvFieldTypeFormatsAvailable.Add("Time", new List<string>() {CsvTypeParser.FORMAT_TRY_ALL,
				"t", "T", "HHmmss", "hmmss", "h:mm tt", "h:mm:ss tt", "h:mm tt",
				"HH':'mm':'ss 'GMT'", "'T'HH':'mm':'ss", "HH':'mm':'ss'Z'",
				"THHmmssZ"});
			this.CsvFieldTypeFormatsAvailable["Time"].Sort();
		}
开发者ID:sanyaade-fintechnology,项目名称:SquareOne,代码行数:27,代码来源:CsvImporterDataSnapshot.cs

示例3: CsvDataSetWriter

 public CsvDataSetWriter()
 {
     config = new CsvConfiguration
     {
         CultureInfo = CultureInfo.InvariantCulture
     };
 }
开发者ID:Pathfinder-Fr,项目名称:WikiExportParser,代码行数:7,代码来源:CsvDataSetWriter.cs

示例4: ExcelParser

 /// <summary>
 /// Creates a new parser using the given <see cref="IXLWorksheet"/> and <see cref="CsvConfiguration"/>.
 /// </summary>
 /// <param name="worksheet">The <see cref="IXLWorksheet"/> with the data.</param>
 /// <param name="configuration">The configuration.</param>
 public ExcelParser(IXLWorksheet worksheet, CsvConfiguration configuration)
 {
     workbook = worksheet.Workbook;
     this.worksheet = worksheet;
     this.configuration = configuration;
     FieldCount = worksheet.RowsUsed().CellsUsed().Max(cell => cell.Address.ColumnNumber);
 }
开发者ID:DustinH,项目名称:CsvHelper.Excel,代码行数:12,代码来源:ExcelParser.cs

示例5: CreateCsv

 internal string CreateCsv(IEnumerable<dynamic> data, CsvConfiguration configuration)
 {
     if (Structure != null && Structure.Count > 0)
         return createCsvWithStructure(data, configuration);
     else
         return createCsvWithoutStructure(data, configuration);
 }
开发者ID:iwate,项目名称:factory-worker,代码行数:7,代码来源:AzureBlobProvider.cs

示例6: Main

        static void Main(string[] args)
        {
            CsvConfiguration cfg = new CsvConfiguration { Delimiter = ";", IsStrictMode = false };
              CsvReader teamsReader = new CsvReader(new StreamReader(Path.Combine(BaseDir, TeamsFilename), Encoding.GetEncoding(1252)), cfg);
              List<TeamRegistration> teams = teamsReader.GetRecords<TeamRegistration>().ToList();

              cfg = new CsvConfiguration { Delimiter = ";", IsStrictMode = false };
              CsvReader checkPointTimesReader = new CsvReader(new StreamReader(Path.Combine(BaseDir, CheckpointTimesFilename), Encoding.GetEncoding(1252)), cfg);
              List<CheckpointTimeRegistration> checkpointTimes = checkPointTimesReader.GetRecords<CheckpointTimeRegistration>().ToList();

              cfg = new CsvConfiguration { Delimiter = ";", IsStrictMode = false };
              CsvReader teamScoresReader = new CsvReader(new StreamReader(Path.Combine(BaseDir, TeamScoresFilename), Encoding.GetEncoding(1252)), cfg);
              List<TeamScoreRegistration> teamScores = teamScoresReader.GetRecords<TeamScoreRegistration>().ToList();

              cfg = new CsvConfiguration { Delimiter = ";", IsStrictMode = false };
              CsvReader checkpointsReader = new CsvReader(new StreamReader(Path.Combine(BaseDir, CheckpointsFilename), Encoding.GetEncoding(1252)), cfg);
              List<CheckpointRegistration> checkpoints = checkpointsReader.GetRecords<CheckpointRegistration>().ToList();

              CheckpointLocationsLoader locationsLoader = new CheckpointLocationsLoader();
              List<CheckpointLocation> checkpointLocations = locationsLoader.LoadCheckpointsFromKML(Path.Combine(BaseDir, CheckpointLocationsFilename));

              RaceDataCalculator converter = new RaceDataCalculator();
              RaceData indecies = converter.CalcuateData(teams, checkpointTimes, teamScores, checkpoints, checkpointLocations);

              JSONDataGenerator generator = new JSONDataGenerator();
              generator.Write(Path.Combine(OutputDir, JSONDataFilename), checkpointLocations, indecies);
        }
开发者ID:JornWildt,项目名称:racetrack,代码行数:27,代码来源:Program.cs

示例7: CsvReader

 public CsvReader(string path, CsvConfiguration config, Domain domain, bool isTestReader)
 {
     Path = path;
     _reader = new CsvHelper.CsvReader(File.OpenText(this.Path), config);
     Domain = domain;
     IsTestReader = isTestReader;
 }
开发者ID:WisonHuang,项目名称:WrapRec,代码行数:7,代码来源:CsvReader.cs

示例8: createCsvWithStructure

        internal string createCsvWithStructure(IEnumerable<dynamic> data, CsvConfiguration configuration)
        {
            var guid = Guid.NewGuid().ToString();
            var builder = new StringBuilder();
            var writer = new CsvHelper.CsvWriter(new StringWriter(builder), configuration);

            foreach (var column in Structure)
                writer.WriteField(column.Name);

            writer.NextRecord();

            foreach (var datum in data)
            {
                var dict = ToDictionary(guid, datum);
                foreach (var column in Structure)
                {
                    var value = dict[column.Name];
                    var str = string.IsNullOrEmpty(column.Format) ? value.ToString()
                            : value.ToString(column.Format);

                    writer.WriteField(str);
                }
                writer.NextRecord();
            }
            return builder.ToString();
        }
开发者ID:iwate,项目名称:factory-worker,代码行数:26,代码来源:AzureBlobProvider.cs

示例9: TestMovieLensSingle

        public void TestMovieLensSingle()
        {
            // step 1: dataset
            var config = new CsvConfiguration()
            {
                Delimiter = "::",
                HasHeaderRecord = true
            };

            // load data
            var trainReader = new CsvReader(Paths.MovieLens1MTrain75, config);
            var testReader = new CsvReader(Paths.MovieLens1MTest25, config, true);

            var container = new DataContainer();
            trainReader.LoadData(container);
            testReader.LoadData(container);

            var startTime = DateTime.Now;

            var splitter = new RatingSimpleSplitter(container);

            //var recommender = new MediaLiteRatingPredictor(new MatrixFactorization());
            var recommender = new LibFmTrainTester(libFmPath: "LibFm.Net.64.exe");

            // evaluation
            var ctx = new EvalutationContext<ItemRating>(recommender, splitter);
            var ep = new EvaluationPipeline<ItemRating>(ctx);
            ep.Evaluators.Add(new RMSE());
            ep.Run();

            var duration = (int)DateTime.Now.Subtract(startTime).TotalMilliseconds;

            Console.WriteLine("RMSE\tDuration\n{0}\t{1}", ctx["RMSE"], duration);
        }
开发者ID:WisonHuang,项目名称:WrapRec,代码行数:34,代码来源:RecSys2015Experiments.cs

示例10: ReadFluorophores

        public static float[] ReadFluorophores(String fileName)
        {
            if(!File.Exists(fileName))
                throw new FileNotFoundException(fileName);

            CsvConfiguration configuration = new CsvConfiguration();

            configuration.HasHeaderRecord = false;
            configuration.TrimFields = true;

            //            List<float[]> fluorophores = new List<float[]>();
            List<float> fluorophores = new List<float>();

            using (CsvReader reader = new CsvReader(new StreamReader(fileName), configuration))
            {
                IEnumerable<DataRecord> dataRecords = reader.GetRecords<DataRecord>();

                foreach (DataRecord dataRecord in dataRecords.ToList())
                {
                    fluorophores.AddRange(dataRecord.ToFloat());
                }
            }

            return fluorophores.ToArray();
        }
开发者ID:jalmar,项目名称:DoM_Utrecht-GPU,代码行数:25,代码来源:CsvData.cs

示例11: Main

        private static void Main(string[] args)
        {
            var c = new CsvConfiguration()
                {
                    HasHeaderRecord = false
                };

            var csv = new CsvReader(new StreamReader(DbIpCityFile), c);

            var items = csv.GetRecords<DbIpCity>();
            var dt = DatabaseManager.GetDataTable();
            
            foreach (var item in items)
            {                
                var row = dt.NewRow();
                row["Ip_Start"] = item.IpStart;
                row["Ip_End"] = item.IpEnd;
                row["city"] = item.City;
                row["region"] = item.Region;
                row["country"] = item.Country;
                row["type"] = item.Type;
                dt.Rows.Add(row);
            }

            DatabaseManager.BulkInsert(ConnString, dt);
        }
开发者ID:JiangLongLiu,项目名称:ZORAN.DB.IP.Importer,代码行数:26,代码来源:Program.cs

示例12: ParseFileAndGetCsvData

        internal static CsvData ParseFileAndGetCsvData(string filePath, UploadConfig config)
        {
            CsvConfiguration configuration = new CsvConfiguration();
            configuration.HasHeaderRecord = true;

            CsvReader csvReader = new CsvReader(new StreamReader(filePath), configuration);

            string[] header = default(string[]);

            List<string[]> rows = new List<string[]>();
            string[] row;
            while (csvReader.Read())
            {
                header = csvReader.FieldHeaders;

                row = new string[header.Length];
                for (int j = 0; j < header.Length; j++)
                {
                    row[j] = csvReader.GetField(j);
                }

                rows.Add(row);
            }

            return new CsvData { Header = header, Rows = rows };
        }
开发者ID:esitefinity,项目名称:ProductUploadPackage,代码行数:26,代码来源:CsvProcessor.cs

示例13: CsvWriter

        public CsvWriter(TextWriter writer, CsvConfiguration configuration)
        {
            Guard.ArgumentNotNull(() => writer);
            Guard.ArgumentNotNull(() => configuration);

            _writer = writer;
            this.Configuration = configuration;
        }
开发者ID:toannguyen241994,项目名称:SmartStoreNET,代码行数:8,代码来源:CsvWriter.cs

示例14: LoadDataFromfCSV

        public static TableData LoadDataFromfCSV(string fileName, string delimeter = null, bool hasHeaderRecord = true,
            bool ignoreQuotes = true, int[] columnIndexes = null, int classIndex=-1)
        {
            var configuration = new CsvConfiguration();
            configuration.Delimiter = delimeter ?? "\t";
            configuration.HasExcelSeparator = false;
            configuration.IgnoreQuotes = ignoreQuotes;
            configuration.HasHeaderRecord = hasHeaderRecord;
            configuration.QuoteNoFields = true;
            using (var reader = new CsvReader(new StreamReader(fileName), configuration))
            {

                var data = new TableData();
                var index = 0;

                while (reader.Read())
                {

                    if (index == 0)
                    {
                        var noOfAttributes = hasHeaderRecord ? reader.FieldHeaders.Length : reader.CurrentRecord.Length;

                        if (columnIndexes == null)
                        {
                            columnIndexes = new int[noOfAttributes];
                            for (var j = 0; j < columnIndexes.Length; j++)
                            {
                                columnIndexes[j] = j;
                            }
                        }

                        for (int column = 0; column < columnIndexes.Length; column++)
                        {
                            var columnName = column == classIndex
                                ? "Class"
                                : hasHeaderRecord
                                    ? reader.FieldHeaders[columnIndexes[column]]
                                    : "Column" + column;
                            data.AddAttribute(columnName);
                        }

                        index++;
                    }

                    var row = data.NewRow();
                    var attributes = data.Attributes.ToArray();
                    for (var columnIndex = 0; columnIndex < columnIndexes.Length; columnIndex++)
                    {
                        var columnName = attributes[columnIndex];
                        row[columnName] = reader.GetField(columnIndexes[columnIndex]);
                    }
                    data.AddRow(row);

                }
                return data;
            }
        }
开发者ID:AdamStefan,项目名称:DataMining,代码行数:57,代码来源:Program.cs

示例15: CreateFileReaderConfiguration

        private static CsvConfiguration CreateFileReaderConfiguration()
        {
            var configuration = new CsvConfiguration();
            configuration.WillThrowOnMissingField = false;
            configuration.SkipEmptyRecords = true;
            configuration.Delimiter = "\t";

            return configuration;
        }
开发者ID:jrolstad,项目名称:traverse,代码行数:9,代码来源:OrcaFileReader.cs


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