Column headers in CSV using fileHelpers library?

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

    I found that you can use the FileHelperAsyncEngine to accomplish this. Assuming your data is a list called "output" of type "outputData", then you can write code that looks like this:

            FileHelperAsyncEngine outEngine = new FileHelperAsyncEngine(typeof(outputData));
            outEngine.HeaderText = "Header1, Header2, Header3";
            outEngine.BeginWriteFile(outputfile);
            foreach (outputData line in output){
                outEngine.WriteNext(line);
            }
            outEngine.Close();
    

提交回复
热议问题