DRY - 不要重复自己
http://www.filehelpers.com/将帮助您处理 csv 文件
例子:
CSV 文件:
10248|VINET|04071996|32.38
10249|TOMSP|05071996|11.61
10250|HANAR|08071996|65.83
10251|VICTE|08071996|41.34
...............
数据传输对象:
[DelimitedRecord("|")]
public class Orders
{
public int OrderID;
public string CustomerID;
[FieldConverter(ConverterKind.Date, "ddMMyyyy")]
public DateTime OrderDate;
public decimal Freight;
}
读者:
FileHelperEngine<Orders> engine = new FileHelperEngine<Orders>();
// to Read use:
Orders[] res = engine.ReadFile("TestIn.txt");
然后:
为你:
[DelimitedRecord(";")]
[IgnoreFirst(1)]
public class RootObject
{
public string Amount { get; set; }
public string P_price { get; set; }
public object Ean { get; set; }
public string Number { get; set; }
public string Name { get; set; }
public int DPH { get; set; }
public int certifikate { get; set; }
public int o1 { get; set; }
public int o2 { get; set; }
public int ZC { get; set; }
}
FileHelperEngine<Orders> engine = new FileHelperEngine<RootObject>();
// to Read use:
Orders[] res = engine.ReadFile("TestIn.txt");