Writing List<T> with all properties in header #1289
Unanswered
mukesh-capsitech
asked this question in
Q&A
Replies: 1 comment
-
Unfortunately, I don't think it is possible to write different header names to the list items like you are trying to do. You could change your code to
Maybe manually writing the header would work for you? using (StringWriter sw = new StringWriter())
{
using (var csv = new CsvWriter(sw))
{
csv.Configuration.HasHeaderRecord = false;
csv.WriteField("Name");
csv.WriteField("Course1.Name");
csv.WriteField("Course1.Price");
csv.WriteField("Course2.Name");
csv.WriteField("Course2.Price");
csv.NextRecord();
csv.WriteRecords<Student>(items);
}
var csvStr = sw.ToString();
Console.WriteLine(csvStr);
Console.ReadKey();
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm looking for example code in the latest version on how to write a mapping between the following class and CSV:
All is working fine for me except the CSV header, for example, I want the result like-
But it gives me the CSV like-
Please guide me to resolve the issue in my code?
Beta Was this translation helpful? Give feedback.
All reactions