FileHelpers:分隔符'|'在场后找不到

时间:2015-01-08 12:46:42

标签: filehelpers

我有一个巨大的CSV文件(1GB),看起来像这样:

1140|2017|0213065852|2001|99|Ä‚/ŮŌçlš˝Ă_Âá'ÄǸ|-3858,18|4015,36|100,17|19,34|0,00|0,00|0,00|40,00|0,00|0,00|0,00|32,57|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|12|12|74|18|24620,65|11903,96|29385,35|10993,94|0,00|-2520,88|0|0100|301|02|0302|N|N|N| | |2001-12-27 00:00:00|N|1140|1313|BG4CSXF0|        |2002-01-01 00:28:13| |0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00
1140|2017|0213065852|2002|99|ľë¸Â‰_gÂýľ)Ľ¸ů_°Ë
…p'™m'î'Ä_|-3799,76|3982,22|461,66|1,48|0,00|0,00|0,00|0,00|0,00|0,00|0,00|100,23|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|27|43|189|20|40140,74|48835,00|69605,32|19312,00|0,00|-3427,87|0|0100|301|02|0303|N|N|N| | |2002-12-27 00:00:00|N|1140|1313|BG4CSXF0|        |2003-01-01 01:35:56| |0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00

当我尝试使用FileHelpers使用以下代码读取此文件时:

FileHelperEngine engine = new FileHelperEngine(typeof(BGDTMDF));
BGDTMDF[] tab = (BGDTMDF[])engine.ReadFile(path);

我收到错误:

  

分隔符'|'在第2行的“MDF_SALDOS_MEDIOS”字段后找不到(记录的字段较少,分隔符错误或下一个字段必须标记为可选)。

我的班级看起来像:

[DelimitedRecord("|")]
public class BGDTMDF
{
    public string MDF_ENTIDAD;
    public string MDF_CENTRO_ALTA;
    public string MDF_CUENTA;
    public string MDF_ANIO;
    public string MDF_MES;

    [FieldNullValue("def")]
    public string MDF_SALDOS_MEDIOS;

    [FieldNullValue("def")]
    public string MDF_SALDO_DISPUE;

    public string MDF_SALDO_MAX_DEU;
    public string MDF_INTE_COBRAD;
    public string MDF_INTE_PAGADO;
    public string MDF_IMPU_RETENI;
}

(这个类只有一部分(如此巨大)。)

任何帮助?

1 个答案:

答案 0 :(得分:1)

我的解决方案是将类中的所有字段标记为[Field Optional]。