如何使用CsvHelper在 asp.net核心中读取和写入csv文件
jum4pzuy1#
你是在问怎么写代码吗?你看过网上的例子吗?请注意,对于某些操作,SoftCircuits.CsvParser比CsvHelper快四倍。下面是使用SoftCircuits.CsvParser读取文件的情况:
string[] columns = null;using (CsvReader reader = new CsvReader(path)){ while (reader.ReadRow(ref columns)) { // Here columns contains an array of string values that // were read from the current line }}
string[] columns = null;
using (CsvReader reader = new CsvReader(path))
{
while (reader.ReadRow(ref columns))
// Here columns contains an array of string values that
// were read from the current line
}
字符串请注意,这两个库都有能力将列直接Map到对象属性,因此您可以创建具有对应于每列的属性的类,并且所有内容都将为您Map。上面的示例只是将列作为字符串数组读取。
1条答案
按热度按时间jum4pzuy1#
你是在问怎么写代码吗?你看过网上的例子吗?
请注意,对于某些操作,SoftCircuits.CsvParser比CsvHelper快四倍。下面是使用SoftCircuits.CsvParser读取文件的情况:
字符串
请注意,这两个库都有能力将列直接Map到对象属性,因此您可以创建具有对应于每列的属性的类,并且所有内容都将为您Map。上面的示例只是将列作为字符串数组读取。