1 Star 0 Fork 0

泡泡时空 / DataTable

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

##C# project for reading and writing CSVs

Fast streaming CSV parser. Libraries for easy reading, writing, and manipulation of CSV files. Is able to handle:

  • CSV file format corner cases including escaped values, newlines, and error recovery
  • Linq and binding CSV rows directly to .NET objects
  • Creating tables from IEnumerable<T>
  • In-memory mutable tables
  • Streaming through large tables.
  • Dictionaries
  • 2D-Dictionary support and converting to CSVs. Great for sparse-arrays.

It's an easier data table than System.Data.DataTable.

The following nuget packages are available:

A few quick examples:

Download as CsvTools from Nuget to include in your C# project:

using DataAccess;
// See methods on DataTable.New for loading a DataTable.
var dt = DataTable.New.ReadLazy(filename); // Fast streaming load a CSV from disk. 

Get a mutable datatable:

MutableDataTable dt = DataTable.New.ReadCsv(filename); // load entire CSV into memory for mutation 
int totalRows = dt.NumRows;

// Includes mutation methods like:
//  CreateColumn, ReorderColumn, KeepColumns, RenameColumn, 
//  GetRow(int rowIndex), KeepRows(Func<T, bool> predicate)

dt.SaveCsv(filename); // write back out

Linq against the rows:

var y = from row in dt.Rows where row["N"] == "3" select row["NSquared"];

Linq with strongly-typed parsing, using RowAs<T>() method:

class Entry
{
  public int N { get; set; }
  public int NSquared { get; set; }
}
int y = (from row in dt.RowsAs<Entry>() where row.N == 3 select row.NSquared).First();

Create a table around an IEnumerable and then save back as a CSV:

var x = from i in Enumerable.Range(1, 5) select new { N = i, NSquared = i * i };
DataTable dt = DataTable.New.FromEnumerable(x);
dt.SaveToStream(Console.Out); // write back out as a CSV

Also includes support for reading an excel file (.xlsx):

var dt = DataTable.New.ReadExcel(@"c:\temp\foo.xlsx");
var names = from row in dt.Rows where int.Parse(row["age"]) > 10 select row["Name"];

See here for more about reading excel.

空文件

简介

Class library for working with tabular data, especially CSV files 展开 收起
C#
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/lanicon/DataTable.git
git@gitee.com:lanicon/DataTable.git
lanicon
DataTable
DataTable
master

搜索帮助