LINQ如何生成csv文件节

时间:2014-03-11 06:20:02

标签: vb.net linq

我遇到了基于该部分生成csv文件的问题。我目前使用LinqToCsv dll生成文件。如何按部分生成文件。请帮忙。感谢。

Currenly我有3节

Header Section
Detail Section 
Footer Section

这是我的代码。

TTMSEntities DB = new TTMSEntities();

CsvFileDescription outputFileDescription = new CsvFileDescription();
outputFileDescription.NoSeparatorChar = false;
outputFileDescription.FirstLineHasColumnNames = true;
outputFileDescription.FileCultureName = "en-US";

List<HeaderRec> list1 = new List<HeaderRec>();
HeaderRec header = new HeaderRec();

header.RecordType = "";
header.RetailerID = "";
header.FileDate = "";
header.FileSequence = "";
header.LastTransRef = "";
list1.Add(header);

var Data = (from p in DB.TT_TNG_KFC_TRANSACTION_UPLOAD
            select new DetailRec
            {
                RecordType = "D",
                TransIDType  ="AA"
            });

List<FooterRec> list2 = new List<FooterRec>();
FooterRec footer = new FooterRec();

footer.RecordType = "T";
footer.TotalAmount = "100";
list2.Add(footer);

CsvContext cc = new CsvContext();

cc.Write(Data, "TestData.csv", outputFileDescription);

如何连接列表?

0 个答案:

没有答案