Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/mr-sb/tinycsv
- Owner: Mr-sB
- License: mit
- Created: 2020-09-14T03:19:52.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-16T06:52:56.000Z (about 2 years ago)
- Last Synced: 2023-03-05T19:29:16.918Z (almost 2 years ago)
- Topics: csharp, csv, csv-parser, donet, toolkit
- Language: C#
- Homepage:
- Size: 52.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# TinyCSV
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.