• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CsvConfiguration类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例6: 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


示例7: 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


示例8: 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


示例9: 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


示例10: 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


示例11: 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


示例12: 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


示例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


示例16: ApplyStandardTopcatCsvConfiguration

        public static CsvConfiguration ApplyStandardTopcatCsvConfiguration(CsvConfiguration config)
        {
            config.Delimiter = "\t";
            config.PrefixReferenceHeaders = true;
            TypeConverterFactory.AddConverter<List<MetadataKeyword>>(new Exporter.MetadataKeywordConverter());
            TypeConverterFactory.AddConverter<List<Extent>>(new Exporter.ExtentListConverter());

            return config;
        }
开发者ID:jncc,项目名称:topcat,代码行数:9,代码来源:TopcatMapping.cs


示例17: Create

        public static ICsvWriter Create(FileInfoBase fileInfo)
        {
            var csvConfiguration = new CsvConfiguration
            {
                Delimiter = ";",
                HasHeaderRecord = true
            };

            var streamWriter = new StreamWriter(fileInfo.OpenWrite(), Encoding.UTF8);
            return new CsvHelper.CsvWriter(streamWriter, csvConfiguration);
        }
开发者ID:ArneD,项目名称:unique-file-records-comparer,代码行数:11,代码来源:CsvWriter.cs


示例18: FieldAttributeTypeConverterTest

        public void FieldAttributeTypeConverterTest()
        {
            var config = new CsvConfiguration();
            config.AttributeMapping<TestClass>();

            Assert.AreEqual( 4, config.Properties.Count );

            Assert.IsInstanceOfType( config.Properties[0].TypeConverterValue, typeof( StringConverter ) );
            Assert.IsInstanceOfType( config.Properties[1].TypeConverterValue, typeof( Int32Converter ) );
            Assert.IsInstanceOfType( config.Properties[2].TypeConverterValue, typeof( Int16Converter ) );
            Assert.IsInstanceOfType( config.Properties[3].TypeConverterValue, typeof( StringConverter ) );
        }
开发者ID:evjan,项目名称:CsvHelper,代码行数:12,代码来源:CsvFieldAttributeMappingTests.cs


示例19: EnsureInternalsAreSetupWhenPassingReaderAndConfigTest

 public void EnsureInternalsAreSetupWhenPassingReaderAndConfigTest()
 {
     using( var stream = new MemoryStream() )
     using( var reader = new StreamReader( stream ) )
     {
         var config = new CsvConfiguration();
         using( var parser = new CsvParser( reader, config ) )
         {
             Assert.Same( config, parser.Configuration );
         }
     }
 }
开发者ID:kharnt0x,项目名称:CsvHelper,代码行数:12,代码来源:CsvParserConstructorTests.cs


示例20: FieldAttributeTypeConverterTest

        public void FieldAttributeTypeConverterTest()
        {
            var config = new CsvConfiguration();
            config.AttributeMapping<TestClass>();

            Assert.Equal( 4, config.Properties.Count );

            Assert.IsType<StringConverter>( config.Properties[0].TypeConverterValue );
            Assert.IsType<Int32Converter>( config.Properties[1].TypeConverterValue );
            Assert.IsType<Int16Converter>( config.Properties[2].TypeConverterValue );
            Assert.IsType<StringConverter>( config.Properties[3].TypeConverterValue );
        }
开发者ID:pwelter34,项目名称:CsvHelper,代码行数:12,代码来源:CsvFieldAttributeMappingTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CsvFileReader类代码示例发布时间:2022-05-24
下一篇:
C# CstNode类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap