如何使用CsvHelper读取 asp.net核心中的csv文件?

2nbm6dog  于 2023-11-20  发布在  .NET
关注(0)|答案(1)|浏览(156)

如何使用CsvHelper在 asp.net核心中读取和写入csv文件

jum4pzuy

jum4pzuy1#

你是在问怎么写代码吗?你看过网上的例子吗?
请注意,对于某些操作,SoftCircuits.CsvParser比CsvHelper快四倍。下面是使用SoftCircuits.CsvParser读取文件的情况:

  1. string[] columns = null;
  2. using (CsvReader reader = new CsvReader(path))
  3. {
  4. while (reader.ReadRow(ref columns))
  5. {
  6. // Here columns contains an array of string values that
  7. // were read from the current line
  8. }
  9. }

字符串
请注意,这两个库都有能力将列直接Map到对象属性,因此您可以创建具有对应于每列的属性的类,并且所有内容都将为您Map。上面的示例只是将列作为字符串数组读取。

相关问题