JoshClose / CsvHelper

Library to help reading and writing CSV files
http://joshclose.github.io/CsvHelper/
Other
4.73k stars 1.06k forks source link

add my report list columns' name as a header to the csv file when the HasHeaderRecord is set to false #2245

Open ElhamJedi opened 6 months ago

ElhamJedi commented 6 months ago

I want to write a report list of objects to csv without header so set the HasHeaderRecord to false. but it's still adding columns' name as a header row.

`using (var writer = new StringWriter()) using (var csv = GetCsvWriter(writer, false)) { csv.Context.RegisterClassMap();

                var data = mapper.Map<List<ExportContactTracingReportModel>>(report) :
                csv.WriteRecords(data);
        }

    public static CsvWriter GetCsvWriter(StringWriter writer, bool hasHeaderRecord = true)
        => new CsvWriter(writer,
            new CsvConfiguration(CultureInfo.InvariantCulture)
            {
                InjectionOptions = InjectionOptions.Strip,
                HasHeaderRecord = hasHeaderRecord,
            });`