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


C# CsvWriter.WriteHeader方法代码示例

本文整理汇总了C#中CsvWriter.WriteHeader方法的典型用法代码示例。如果您正苦于以下问题:C# CsvWriter.WriteHeader方法的具体用法?C# CsvWriter.WriteHeader怎么用?C# CsvWriter.WriteHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvWriter的用法示例。


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

示例1: CompareChangingValues

        public void CompareChangingValues()
        {
            UserAssist assist = new UserAssist();
            using(CsvWriter writer = new CsvWriter(new StreamWriter(File.Open("ChangingValues.csv", FileMode.Create))))
            {
                writer.WriteHeader<ValueLetter>();
                var snap1Values =
                    assist.Snapshot("snap1.csv")
                    .FindProgram("cmd.exe")
                    .GetValue();

                WaitOpenThenKill("cmd.exe");

                var snap2Values = assist.Snapshot("snap2.csv")
                                        .FindProgram("cmd.exe")
                                        .GetValue();
                for(int i = 0 ; i < snap1Values.Length ; i++)
                {
                    writer.WriteRecord(new ValueLetter()
                    {
                        Position = i,
                        Value1 = snap1Values[i].ToString("X2"),
                        Value2 = snap2Values[i].ToString("X2"),
                        IsDiff = (snap1Values[i] != snap2Values[i]) ? "x" : ""
                    });
                }
            }
            Process.Start("ChangingValues.csv");
        }
开发者ID:NicolasDorier,项目名称:userassist,代码行数:29,代码来源:UnitTest1.cs

示例2: GeneratePerformaceReport

        static void GeneratePerformaceReport()
        {
            var iterations = 50;


            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var writer = new StreamWriter(stream))
            using (var csv = new CsvWriter(writer))
            {
                csv.WriteHeader(typeof(PerformaceTestResult));

              /*  csv.WriteRecords(DoTestsForSettings(iterations, false, false, false));
                csv.WriteRecords(DoTestsForSettings(iterations, false, false, true));
                csv.WriteRecords(DoTestsForSettings(iterations, false, true, false));
                csv.WriteRecords(DoTestsForSettings(iterations, false, true, true));


                csv.WriteRecords(DoTestsForSettings(iterations, true, false, false));
                csv.WriteRecords(DoTestsForSettings(iterations, true, false, true));

                csv.WriteRecords(DoTestsForSettings(iterations, true, true, false));
                */
                csv.WriteRecords(DoTestsForSettings(iterations, true, true, true));
                writer.Flush();
                stream.Position = 0;
                var text = reader.ReadToEnd();
                File.WriteAllText("Report.csv", text);
            }
        }
开发者ID:christofur,项目名称:SuperchargedReact.Net,代码行数:30,代码来源:Program.cs

示例3: DownloadCSVTemplate

        /// <summary>
        /// Downloads the CSV template for assignments.
        /// </summary>
        /// <author> Cristian Araya Fuentes </author>
        /// <returns> Csv file </returns>
        public FileResult DownloadCSVTemplate()
        {
            String vTemplateFileName = "plantillaAsignacion.csv";
            byte[] vFileSize;
            int vIDEntity = getEntityID(Request.Cookies["Entidad"].Value);
            int vIDPeriod = Int32.Parse(Request.Cookies["Periodo"].Value);

            IEnumerable<DataCSV> vGroups = getGroupesPeriod(vIDPeriod, vIDEntity);

            using (Stream memoryStream = new MemoryStream())
            {
                StreamWriter streamWriter = new StreamWriter(memoryStream, Encoding.UTF8);

                var vWriter = new CsvWriter(streamWriter);
                vWriter.Configuration.Encoding = Encoding.UTF8;
                //Write the CSV's file header
                vWriter.WriteHeader(typeof(DataCSV));

                //Write each group
                foreach (DataCSV group in vGroups)
                {
                    vWriter.WriteRecord(group);
                }

                vWriter.NextRecord();
                streamWriter.Flush();
                memoryStream.Flush();
                memoryStream.Position = 0;
                vFileSize = new byte[memoryStream.Length];
                memoryStream.Read(vFileSize, 0, vFileSize.Length);
                streamWriter.Close();
                streamWriter.Dispose();
            }
            return File(vFileSize, System.Net.Mime.MediaTypeNames.Application.Octet, vTemplateFileName);
        }
开发者ID:saca-ae,项目名称:SACA-AE_Web-App_v2,代码行数:40,代码来源:CSVController.cs

示例4: FiltersForLineItemType

        public void FiltersForLineItemType()
        {
            // Arrange
            var sw = new StringWriter();
            using (var csv = new CsvWriter(sw))
            {
                var lineItems = new[]
                {
                    new LineItem {RecordType = "Dummy"},
                    new LineItem {RecordType = "LineItem", RecordId = "Hoojey"}
                };
                csv.WriteHeader<LineItem>();
                csv.WriteRecords(lineItems);
            }

            // Act
            List<LineItem> parsedItems;
            using (var reader = new StringReader(sw.ToString()))
            {
                using (var parser = new LineItemCsvParser(reader))
                {
                    parsedItems = parser.GetLineItems().ToList();
                }
            }

            // Assert
            parsedItems.Count.Should().Be(1);
            parsedItems[0].RecordId.Should().Be("Hoojey");
        }
开发者ID:nelsonwellswku,项目名称:stack-it-net,代码行数:29,代码来源:LineItemCsvParserTests.cs

示例5: ExportProductsTest

        public void ExportProductsTest()
        {
            var searchService = GetSearchService();
            var categoryService = GetCategoryService();
            var itemService = GetItemService();
            var result = searchService.Search(new SearchCriteria { CatalogId = "Sony", CategoryId = "66b58f4c-fd62-4c17-ab3b-2fb22e82704a", Skip = 0, Take = 10, ResponseGroup = coreModel.SearchResponseGroup.WithProducts });
            var importConfiguration = GetMapConfiguration();

            using (var csvWriter = new CsvWriter(new StreamWriter(@"c:\Projects\VCF\vc-community\PLATFORM\Modules\Catalog\VirtoCommerce.CatalogModule.Test\products.csv")))
            {
                var csvProducts = new List<CsvProduct>();
                foreach (var product in result.Products)
                {
                    var fullLoadedProduct = itemService.GetById(product.Id, ItemResponseGroup.ItemLarge);
                    csvProducts.Add(new CsvProduct(fullLoadedProduct, null, null, null));
                }

                importConfiguration.PropertyCsvColumns = csvProducts.SelectMany(x => x.PropertyValues).Select(x => x.PropertyName).Distinct().ToArray();
                csvWriter.Configuration.Delimiter = ";";
                csvWriter.Configuration.RegisterClassMap(new CsvProductMap(importConfiguration));

                csvWriter.WriteHeader<CsvProduct>();
                foreach (var product in csvProducts)
                {
                    csvWriter.WriteRecord(product);
                }

            }
        }
开发者ID:adwardliu,项目名称:vc-community,代码行数:29,代码来源:ImportExportTest.cs

示例6: ExportCategories

        public void ExportCategories(string path, bool zipIt = true)
        {
            var fileName = "Categories_" + DateTime.Now.ToString("yyyyMMddTHHmmss");
            using (var file = File.CreateText(Path.Combine(path, fileName + ".csv")))
            {
                var csv = new CsvWriter(file);
                csv.Configuration.RegisterClassMap<CategoryCsvMap>();
                csv.WriteHeader<Category>();

                foreach (var category in categoryService.FindAll().OrderBy(c => c.Id).InChunksOf(100))
                {
                    csv.WriteRecord(category);
                }
            }

            if (zipIt)
            {
                using (var zip = new ZipFile(Path.Combine(path, fileName + ".zip")))
                {
                    zip.AddFile(Path.Combine(path, fileName + ".csv"), "").FileName = "Categories.csv";
                    zip.Save();
                }

                File.Delete(Path.Combine(path, fileName + ".csv"));
            }
        }
开发者ID:alin-rautoiu,项目名称:Cart42,代码行数:26,代码来源:DataExportService.cs

示例7: ExportHeader

        public void ExportHeader(TextWriter writer)
        {
            var csv = new CsvWriter(writer);

            TopcatMapping.ApplyStandardTopcatCsvConfiguration(csv.Configuration);

            csv.WriteHeader<Record>();
        }
开发者ID:jncc,项目名称:topcat,代码行数:8,代码来源:Exporter.cs

示例8: To

 public void To(string file, List<GameStats> stats)
 {
     using (var writer = new StreamWriter(file))
     {
         using (var csv = new CsvWriter(writer))
         {
             csv.Configuration.RegisterClassMap<GameStatsMap>();
             csv.WriteHeader<GameStats>();
             csv.WriteRecords(stats);
         }
     }
 }
开发者ID:ChuckFork,项目名称:hdt-plugin-statsconverter,代码行数:12,代码来源:CSVExporter.cs

示例9: Write

 public void Write(IEnumerable<DataRecord> list)
 {
     using (var streamWriter = new StreamWriter(FilePath, false, Encoding.Default))
     {
         var csvWriter = new CsvWriter(streamWriter);
         csvWriter.WriteHeader<DataRecord>();
         foreach (var item in list)
         {
             csvWriter.WriteRecord(item);
         }
     }
 }
开发者ID:andrewtovkach,项目名称:EpamTraining,代码行数:12,代码来源:ReadWriter.cs

示例10: WriteTo

 public static void WriteTo(this DiffResult result, string file)
 {
     using(var fs = File.Open(file, FileMode.Create))
     {
         var streamWriter = new StreamWriter(fs);
         CsvWriter writer = new CsvWriter(streamWriter);
         writer.WriteHeader(typeof(DiffBlock));
         foreach(var block in result.DiffBlocks)
         {
             writer.WriteRecord(block);
         }
         streamWriter.Flush();
     }
 }
开发者ID:NicolasDorier,项目名称:userassist,代码行数:14,代码来源:Extensions.cs

示例11: ExportGenreConfig

        public void ExportGenreConfig(Stream memortStream)
        {
            var records = GetList();
            using (var txtWriter = new StreamWriter(memortStream))
            {
                using (var csvWriter = new CsvWriter(txtWriter))
                {
                    csvWriter.Configuration.HasHeaderRecord = true;
                    csvWriter.Configuration.RegisterClassMap<GenreCsvMap>();
                    csvWriter.WriteHeader(typeof(Genre));

                    foreach (var record in records)
                    {
                        csvWriter.WriteRecord(record);
                    }
                }
            }
        }
开发者ID:jvaleroso,项目名称:MusicStoreAngularVersion,代码行数:18,代码来源:GenreService.cs

示例12: Download

        public FileContentResult Download(DateTime start, DateTime end)
        {
            var textWriter = new StringWriter();

            var csv = new CsvWriter(textWriter);
            csv.Configuration.Delimiter = ";";
            csv.WriteHeader<QueryLogItem>();

            var queryLogItems = _queryLogRepository.GetByDateRange(start, end);

            foreach (var queryLogItem in queryLogItems)
            {
                csv.WriteRecord(queryLogItem);
            }

            textWriter.Close();

            return File(new System.Text.UTF8Encoding().GetBytes(textWriter.ToString()), "text/csv", string.Format("log {0:yyyy-MM-dd} -- {1:yyyy-MM-dd}.csv", start, end));
        }
开发者ID:kennisnet,项目名称:Sparql-Query-Api,代码行数:19,代码来源:LogController.cs

示例13: DoExport

		public void DoExport(Stream outStream, CsvExportInfo exportInfo, Action<ExportImportProgressInfo> progressCallback)
		{
			var prodgressInfo = new ExportImportProgressInfo
			{
				Description = "loading products..."
			};

			var streamWriter = new StreamWriter(outStream, Encoding.UTF8, 1024, true);
			streamWriter.AutoFlush = true;

			using (var csvWriter = new CsvWriter(streamWriter))
			{
				//Notification
				progressCallback(prodgressInfo);

				//Load all products to export
				var products = LoadProducts(exportInfo.CatalogId, exportInfo.CategoryIds, exportInfo.ProductIds);
				var allProductIds = products.Select(x => x.Id).ToArray();

				//Load prices for products
				var allProductPrices = new List<Price>();

				prodgressInfo.Description = "loading prices...";
				progressCallback(prodgressInfo);

				var priceEvalContext = new PriceEvaluationContext
				{
					ProductIds = allProductIds,
					PricelistIds = exportInfo.PriceListId == null ? null : new string[] { exportInfo.PriceListId },
					Currency = exportInfo.Currency
				};
				allProductPrices = _pricingService.EvaluateProductPrices(priceEvalContext).ToList();


				//Load inventories
				var allProductInventories = new List<InventoryInfo>();

				prodgressInfo.Description = "loading inventory information...";
				progressCallback(prodgressInfo);

				allProductInventories = _inventoryService.GetProductsInventoryInfos(allProductIds).Where(x => exportInfo.FulfilmentCenterId == null ? true : x.FulfillmentCenterId == exportInfo.FulfilmentCenterId).ToList();


				//Export configuration
				exportInfo.Configuration.PropertyCsvColumns = products.SelectMany(x => x.PropertyValues).Select(x => x.PropertyName).Distinct().ToArray();

				csvWriter.Configuration.Delimiter = exportInfo.Configuration.Delimiter;
				csvWriter.Configuration.RegisterClassMap(new CsvProductMap(exportInfo.Configuration));

				//Write header
				csvWriter.WriteHeader<CsvProduct>();

				prodgressInfo.TotalCount = products.Count();
				var notifyProductSizeLimit = 50;
				var counter = 0;
				foreach (var product in products)
				{
					try
					{
						var csvProduct = new CsvProduct(product, _blobUrlResolver, allProductPrices.FirstOrDefault(x => x.ProductId == product.Id), allProductInventories.FirstOrDefault(x => x.ProductId == product.Id));
						csvWriter.WriteRecord(csvProduct);
					}
					catch (Exception ex)
					{
						prodgressInfo.Errors.Add(ex.ToString());
						progressCallback(prodgressInfo);
					}

					//Raise notification each notifyProductSizeLimit products
					counter++;
					prodgressInfo.ProcessedCount = counter;
					prodgressInfo.Description = string.Format("{0} of {1} products processed", prodgressInfo.ProcessedCount, prodgressInfo.TotalCount);
					if (counter % notifyProductSizeLimit == 0 || counter == prodgressInfo.TotalCount)
					{
						progressCallback(prodgressInfo);
					}
				}
			}
		}
开发者ID:adwardliu,项目名称:vc-community,代码行数:79,代码来源:CsvCatalogExporter.cs

示例14: WriteRecordSepTest

        public void WriteRecordSepTest()
        {
            using( var stream = new MemoryStream() )
            using( var reader = new StreamReader( stream ) )
            using( var writer = new StreamWriter( stream ) )
            using( var csv = new CsvWriter( writer ) )
            {
                var record = new Simple
                {
                    Id = 1,
                    Name = "one",
                };

                csv.Configuration.Delimiter = ";";
                csv.Configuration.HasExcelSeparator = true;
                csv.WriteExcelSeparator();
                csv.WriteHeader<Simple>();
                csv.WriteRecord( record );

                writer.Flush();
                stream.Position = 0;

                var text = reader.ReadToEnd();

                Assert.AreEqual( "sep=;\r\nId;Name\r\n1;one\r\n", text );
            }
        }
开发者ID:KPK-Teamwork-Team-Bajic,项目名称:KPK-Teamwork,代码行数:27,代码来源:ExcelCompatibleTests.cs

示例15: SearchModule

        public SearchModule()
            : base("/api")
        {
            this.RequiresAuthentication();
            Get["/{Location}/{Start}/{End}/{Interval}/SearchData"] = _ =>
            {
                var loc = _.Location;
                string s = _.Start;
                DateTime start = _.Start;
                DateTime end = _.End;
                var interval = _.Interval;

                Guid g;
                Guid.TryParse(loc, out g);
                if (interval == "60")
                {
                    end = end.AddDays(1);
                    List<HistoricalTransfer.DaySelectionData> data = HistoricalTransfer.GetDataHr(loc, start, end, interval);
                    return Response.AsJson(data);
                }
                if (interval == "15")
                {
                    List<DashboardObject> data = HistoricalTransfer.GetDataQtr(loc, start, end, interval);

                    return Response.AsJson(data);

                }

                return HttpStatusCode.InternalServerError;

            };

            Get["/{Location}/{Start}/{Interval}/LaneData"] = _ =>
            {
                var loc = _.Location;
                string s = _.Start;
                DateTime start = _.Start;
                var interval = _.Interval;

                Guid g;
                Guid.TryParse(loc, out g);

                try
                {
                    List<LaneObject> data = HistoricalTransfer.GetLaneData(loc, start, interval);
                    return Response.AsJson(data);
                }
                catch (Exception ex)
                {
                    return HttpStatusCode.InternalServerError;
                }

            };

            Get["/exportData/{id}/{from}/{to}/{interval}/{type}"] = _ =>
            {
                var id = _.id;
                DateTime start = _.from;
                DateTime end = _.to;
                var interval = _.Interval;
                var type = _.type;

                Guid g;
                Guid.TryParse(id, out g);
                var response = new Response();
                response.Headers.Add("Content-Disposition", "attachment; filename=ExportedData" + DateTime.Now.ToString("dd MMM yyyy HH mm") + ".csv");
                response.ContentType = "application/octet-stream";
                try
                {

                    //string[] names = new string[] { "Time Period Start", "Time Period End", "Passenger Count", "Tray Count",
                    //    "Tray Reject Count" , "Passenger Forecast", "Queue Time", "Image PP", "Variance", "Hourly Flow",
                    //    "Image Reject", "TIP Images", "TIP Hit", "Tip Score", "Amd Open","Amd Forecast",
                    //"XRay Open", "XRay Forecast"};

                    List<DashboardObject> data = HistoricalTransfer.GetDataQtr(id, start, end, interval);

                    if (type == "1")
                    {
                        response.Contents = stream =>
                        {
                            var csv = new CsvWriter(new StreamWriter(stream));
                            csv.Configuration.HasHeaderRecord = true;
                            csv.WriteHeader<DashboardObject>();
                            csv.Configuration.Delimiter = ",";
                            foreach (var row in data)
                            {
                                csv.WriteRecord(row);
                            }

                        };
                        return response;
                    }
                    if (type == "2")
                        {
                            //List<LaneObject> data = HistoricalTransfer.GetLaneData(id, start, interval);

                            foreach (var a in data)
                            {
                                a.LaneObject = HistoricalTransfer.GetLaneData(id, a.TimePeriodStart, interval);
//.........这里部分代码省略.........
开发者ID:MHAWeb,项目名称:AGS,代码行数:101,代码来源:SearchModule.cs


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