Column headers in CSV using fileHelpers library?

后端 未结 6 1779
醉话见心
醉话见心 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:20

    List myList = new List();
    FileHelperEngine engine = new FileHelperEngine(typeof(MyClass));
    String[] fieldNames = Array.ConvertAll(typeof(MyClass).GetFields(), delegate(FieldInfo fo) { return fo.Name; });
    engine.HeaderText = String.Join(";", fieldNames);
    engine.WriteFile(MapPath("MyClass.csv"), myList);
    

提交回复
热议问题