Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mr-sb/tinycsv

Tiny CSV toolkit for .NET. Easy to read and write CSV table. Support cells contain comma and double quote characters, and also support multiline cells form.
https://github.com/mr-sb/tinycsv

csharp csv csv-parser donet toolkit

Last synced: about 2 months ago
JSON representation

Tiny CSV toolkit for .NET. Easy to read and write CSV table. Support cells contain comma and double quote characters, and also support multiline cells form.

Awesome Lists containing this project

README

        

# TinyCSV


Version 1.3.2

Tiny CSV toolkit for .NET. Easy to read and write CSV table.

## Feature
* Easy to read and write csv table.
* Custom header lines.
* Support choose new line style:

| Environment | Unix | NonUnix |
| :-----------------: | :----: | :-------: |
| Environment.NewLine | \n | \r\n |
* Support cell's form:

| contain cells separators | contain double quotes | custom cells separator | multiline |
| :----------------------: | :-------------------: | :--------------------: | :-------: |
| √ | √ | √ | √ |
* You can custom cells separator. Default is comma.
* You can choose whether to support multiline cells. Default is support.

## Usage
More examples can be found in the TinyCSV.Example.
### Reading a CSV file
```c#
var csv = File.ReadAllText("sample.csv");
//Create csv reader form csv content, custom cell separator.
CSVTableReader csvTableReader = new CSVTableReader(csv, 2, ',');
```
### Writing a CSV file
```c#
//Create a empty csv writer.
CSVTableWriter csvTableWriter = new CSVTableWriter()
//Add headers.
.AddHeader(new CSVRecordWriter {"Data1", "Data2"})
.AddHeader(new CSVRecordWriter {"string", "int"})
//Add records.
.AddRecord(new CSVRecordWriter()
.Add("string with double quote\" and comma, and \n\\n and \r\n\\r\\n")
.Add("1"));
//Get csv form string, custom cell separator and choose new line style.
string csv = csvTableWriter.GetEncodeTable(',', NewLineStyle.NonUnix);
//Create csv writer from csv content.
CSVTableWriter csvTableWriter2 = new CSVTableWriter(csv, 2);
```

## Requirements
TinyCSV currently targets and supports
* .NET Framework 4.0 and above.