抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

C# 逐行读取 CSV 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using Microsoft.Office.Interop.Excel;
using Microsoft.VisualBasic.FileIO;

public List<string> ReadFromCsv()
{
var partList = new List<string>();
using (TextFieldParser parser = new TextFieldParser(@"D:/List.csv"))
{
parser.TextFieldType = FieldType.Delimited;
parser.SetDelimiters(",");
while (!parser.EndOfData)
{
string[] fileds = parser.ReadFields();
foreach (var filed in fileds)
{
partList.Add(filed);
}
}
}
return partList;
}

评论