Column headers in CSV using fileHelpers library?

后端 未结 6 1775
醉话见心
醉话见心 2020-12-23 13:38

Is there a built-in field attribute in the FileHelper library which will add a header row in the final generated CSV?

I have Googled and didn\'t find much info on it

6条回答
  •  不思量自难忘°
    2020-12-23 14:00

    I don't know if you still need this, but here is the way FileHelper is working : To include headers of columns, you need to define a string with headers delimited the same way as your file. For example with '|' as delimiter :

     public const string HeaderLine = @"COLUMN1|COLUMN2|COLUMN3|...";
    

    Then, when calling your engine :

    DelimitedFileEngine _engine = new DelimitedFileEngine { HeaderText = HeaderLine };
    

    If you don't want to write the headers, just don't set the HeaderText attribute on the engine.

提交回复
热议问题