在c#中读/写CSV /制表符分隔的文件 [英] Reading/writing CSV/tab delimited files in c#

查看:571
本文介绍了在c#中读/写CSV /制表符分隔的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从CSV /制表符分隔文件读取,并从.net中写入这样的文件。

I need to read from a CSV/Tab delimited file and write to such a file as well from .net.

难度是我不知道每个文件的结构,并需要将cvs / tab文件写入一个datatable,这是FileHelpers库似乎不支持。

The difficulty is that I don't know the structure of each file and need to write the cvs/tab file to a datatable, which the FileHelpers library doesn't seem to support.

我已经写了对于使用OLEDB的Excel,但不能真正看到为此写一个标签文件的方法,因此将返回到库。

I've already written it for Excel using OLEDB, but can't really see a way to write a tab file for this, so will go back to a library.

任何人都可以帮助建议?

Can anyone help with suggestions?

推荐答案

我使用这个 CsvReader ,它是真的很好,很好的配置。它对于字符串和分隔符的各种转义都表现良好。在其他快速和肮脏的实现逃脱是穷人,但这个lib是真的伟大的阅读。有了一些额外的代码,你也可以添加一个缓存,如果你需要。

I used this CsvReader, it is really great and well configurable. It behaves well with all kinds of escaping for strings and separators. The escaping in other quick and dirty implementations were poor, but this lib is really great at reading. With a few additional codelines you can also add a cache if you need to.

不支持写入,但是实现自己很简单。或者启发此代码

Writing is not supported but it rather trivial to implement yourself. Or inspire yourself from this code.

这篇关于在c#中读/写CSV /制表符分隔的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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