忽略使用Filehelpers在CSV最后几行,如果他们不输入 [英] Ignoring last lines in CSV using Filehelpers if they aren't input

查看:137
本文介绍了忽略使用Filehelpers在CSV最后几行,如果他们不输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立使用FileHelpers解析CSV文件的程序,它可以创造奇迹,但我运行到一个问题。
部分文件 - 但不是全部 - 具有许多在与不属于实际字段的信息结束额外的行

I built a program using FileHelpers to parse CSV files and it works wonders, except I'm running into an issue. Some of the files - but not all - have a number of extra lines in the end with information that does not pertain to actual fields.

像这样

...
31,4104019, ,,1043,,,0,,Ventas Total Credito,1,1,277.98,0,0,0,0,21.5040000000,V,
31, ,11212302,,1043,,,0,,Ventas Total Credito,1,1,33.28,0,0,0,0,21.5040000000,V,
31, ,11212307,,1043,,,0,,Ventas Total Credito,1,1,277.98,0,0,0,0,21.5040000000,V,

;Importado="01/11/2013"
 //blank line here too

我知道FileHelpers有在

I know FileHelpers has the

[IgnoreLast(3)] 
public class whatever...

选项,但是因为只有一些文件有那些额外的3条线路,使用这个对所有可能导致在过去的3个记录被忽略了一段文件。

option, but as only some of the files have those extra 3 lines, Using this for all could result in the last 3 records being ignored for some files.

有没有办法告诉它时忽略行?或者我应该先分别读取该文件,并删除这些行自己?

Is there any way to tell it when to ignore a line? Or should I read the file separately first and remove those lines myself?

推荐答案

您可以使用 BeforeReadRecord 事件或记录的 INotifyRead 的界面,更简单执行

You can use the BeforeReadRecord event or implement in the record INotifyRead interface that is more simple.

在这两种情况下使用e.SkipThisRecord = TRUE;在您需要放弃

In both cases use e.SkipThisRecord = true; in the cases that you need to discard

这篇关于忽略使用Filehelpers在CSV最后几行,如果他们不输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆