csvhelper

CsvHelper wrap all valus with quotes

假装没事ソ 提交于 2020-07-03 03:20:10
问题 I am using CsvHelper I need to wrap all values with quotes. Is that possible? Data = is a List using (StreamWriter textWriter = new StreamWriter(path)) { textWriter.BaseStream.Write(p, 0, p.Length); // var dt = new DataTable(); var csv = new CsvWriter(textWriter); csv.WriteRecords(Data); textWriter.Flush(); textWriter.Close(); } Thanks 回答1: There is a config value called ShouldQuote where you can determine on a field level if it should be quoted. void Main() { var records = new List<Foo> {

Setting column order for CSVHelper

谁都会走 提交于 2020-06-27 07:41:24
问题 I am using CSVMapper to output the objects within a dictionary: using (TextWriter writer = new StreamWriter($"somefile.csv")) { var csvDP = new CsvWriter(writer); csvDP.WriteHeader<NodeDPCount>(); csvDP.NextRecord(); foreach (NodeDPCount dpItem in dp.Values) { csvDP.WriteRecord(dpItem); csvDP.NextRecord(); } } It is a simple class with fields like ID, Name, Age, etc. However, the output of the columns is in an order I do not like (e.g. ID is not first) and I want to specify which column is

CsvHelper : Adding a title using CsvHelper

心已入冬 提交于 2020-05-08 16:02:01
问题 I am using CsvHelper to convert dapper objects to CsvFiles. I am using classmaps to map properties for indices and name mapping. The issue is I need a row with the table title before the records are written as mentioned below: My old code without the title: using (var writer = new StreamWriter(@"C:\Users\NPandian\Desktop\test.csv", false, System.Text.Encoding.UTF8)) using (var csvWriter = new CsvWriter(writer)) { var ReportName = "Test Class"; csvWriter.Configuration.RegisterClassMap(classMap

CsvHelper : Adding a title using CsvHelper

允我心安 提交于 2020-05-08 16:01:06
问题 I am using CsvHelper to convert dapper objects to CsvFiles. I am using classmaps to map properties for indices and name mapping. The issue is I need a row with the table title before the records are written as mentioned below: My old code without the title: using (var writer = new StreamWriter(@"C:\Users\NPandian\Desktop\test.csv", false, System.Text.Encoding.UTF8)) using (var csvWriter = new CsvWriter(writer)) { var ReportName = "Test Class"; csvWriter.Configuration.RegisterClassMap(classMap

Why CsvHelper not reading from MemoryStream?

本小妞迷上赌 提交于 2020-03-18 11:51:10
问题 I am trying to convert an uploaded csv file to an object, so i can save in db. In the controller I am using CsvHeler But looks like this only works if I first save the file and read from it. CsvHelper is not able to process the file contents directly from memory stream. In the code below the first GetRecords returns empty [HttpPost] [Route(ApiRoutes.EodVariationMarginPlugs)] public async Task<IActionResult> UploadPlugAsync(IFormFile filePayload) { if (filePayload.Length > 0) { using (var

Why CsvHelper not reading from MemoryStream?

扶醉桌前 提交于 2020-03-18 11:50:33
问题 I am trying to convert an uploaded csv file to an object, so i can save in db. In the controller I am using CsvHeler But looks like this only works if I first save the file and read from it. CsvHelper is not able to process the file contents directly from memory stream. In the code below the first GetRecords returns empty [HttpPost] [Route(ApiRoutes.EodVariationMarginPlugs)] public async Task<IActionResult> UploadPlugAsync(IFormFile filePayload) { if (filePayload.Length > 0) { using (var

why cant i convert from 'System.IO.StreamWriter' to 'CsvHelper.ISerializer'?

岁酱吖の 提交于 2020-03-01 02:09:38
问题 Trying to write the contents of people to a CSVfile and then export it, however i'm getting a build error and its failing. the error is: cannot convert from 'System.IO.StreamWriter' to 'CsvHelper.ISerializer' Not sure why this is happening unless as i'm certain i've done it this way loads of times. private void ExportAsCSV() { using (var memoryStream = new MemoryStream()) { using (var writer = new StreamWriter(memoryStream)) { using (var csv = new CsvHelper.CsvWriter(writer)) { csv

why cant i convert from 'System.IO.StreamWriter' to 'CsvHelper.ISerializer'?

梦想与她 提交于 2020-03-01 02:09:38
问题 Trying to write the contents of people to a CSVfile and then export it, however i'm getting a build error and its failing. the error is: cannot convert from 'System.IO.StreamWriter' to 'CsvHelper.ISerializer' Not sure why this is happening unless as i'm certain i've done it this way loads of times. private void ExportAsCSV() { using (var memoryStream = new MemoryStream()) { using (var writer = new StreamWriter(memoryStream)) { using (var csv = new CsvHelper.CsvWriter(writer)) { csv

CsvHelper try to export in csv a list which contain another list .net

坚强是说给别人听的谎言 提交于 2020-02-02 12:55:09
问题 I implement a web api in .Net Framework using csvHelper to export a csv. I have the classes public class StudentInfo { public Student Student {get;set;} public Courses[] Courses { get; set; } } public class Student { public string Id {get;set;} public string Name{ get; set; } } public class Course { public string CourseId {get;set;} public string CourseName{ get; set; } } I have a method which return a List public List<StudentInfo> FetchStudentInfo() { //bla bla } Now I want to export in a

CsvHelper try to export in csv a list which contain another list .net

爱⌒轻易说出口 提交于 2020-02-02 12:54:07
问题 I implement a web api in .Net Framework using csvHelper to export a csv. I have the classes public class StudentInfo { public Student Student {get;set;} public Courses[] Courses { get; set; } } public class Student { public string Id {get;set;} public string Name{ get; set; } } public class Course { public string CourseId {get;set;} public string CourseName{ get; set; } } I have a method which return a List public List<StudentInfo> FetchStudentInfo() { //bla bla } Now I want to export in a