需要每条记录的 CSV 文件

CSV File per record required

我正在使用文件助手库构建一个 csv,但我需要为每条记录创建一个 csv 文件。

var engine = new FileHelperEngine(typeof(SalesOrders));
int count = 0;
foreach (SalesOrders item in purchaseOrder)
{
     count++;
     string fileName = "SalesOrder_" + item.OrderNumber.ToString() + ".csv";

     var feng = new FileHelperEngine<SalesOrders>();
     string str1 = feng.WriteString(purchaseOrder);
     List<SalesOrdersItems> _orderItemsForExport = SopOrderItems.Where(a => a.ORDER_NUMBER.ToString() == item.OrderNumber).ToList();

}

然而这一行

string str1 = feng.WriteString(purchaseOrder);

正在打印所有内容而不是每个 csv 的项目。我觉得只是我的逻辑不对。

foreach (SalesOrders item in purchaseOrder)
            {
                using (StreamWriter sw = new StreamWriter($"SalesOrder_{item.OrderNumber.ToString()}.csv"))
                {
                    var lines = TakeAllStuffFrom(item); // like a collection of $"{SalesOrder.FirstField.Trim()};{SalesOrder.SecondField.Trim()}";

                    foreach (var line in lines)
                    {
                        sw.WriteLine(line);
                    }
                }
            }

写下您希望在 csv 文件中显示的内容的示例,我们会找出答案:)