Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kris701/csvtoolssharp
Some simple tools to work with CSV files
https://github.com/kris701/csvtoolssharp
csharp csv
Last synced: 22 days ago
JSON representation
Some simple tools to work with CSV files
- Host: GitHub
- URL: https://github.com/kris701/csvtoolssharp
- Owner: kris701
- License: mit
- Created: 2024-03-21T16:30:12.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-03-31T08:50:10.000Z (11 months ago)
- Last Synced: 2024-11-20T06:07:38.820Z (3 months ago)
- Topics: csharp, csv
- Language: C#
- Homepage:
- Size: 76.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[![Build and Publish](https://github.com/kris701/CSVToolsSharp/actions/workflows/dotnet-desktop.yml/badge.svg)](https://github.com/kris701/CSVToolsSharp/actions/workflows/dotnet-desktop.yml)
![Nuget](https://img.shields.io/nuget/v/CSVToolsSharp)
![Nuget](https://img.shields.io/nuget/dt/CSVToolsSharp)
![GitHub last commit (branch)](https://img.shields.io/github/last-commit/kris701/CSVToolsSharp/main)
![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/m/kris701/CSVToolsSharp)
![Static Badge](https://img.shields.io/badge/Platform-Windows-blue)
![Static Badge](https://img.shields.io/badge/Platform-Linux-blue)
![Static Badge](https://img.shields.io/badge/Framework-dotnet--8.0-green)CSV Tools Sharp is a little project to manipulate and output CSV files.
You can find it on the [NuGet Package Manager](https://www.nuget.org/packages/CSVToolsSharp/) or the [GitHub Package Manager](https://github.com/kris701/CSVToolsSharp/pkgs/nuget/CSVToolsSharp).# How to Use
The package is inspired by that of [System.Text.Json](https://www.nuget.org/packages/System.Text.Json/9.0.0-preview.2.24128.5), where you can access two primary static methods, `CSVSerialiser.Deserialise` and `CSVSerialiser.Serialise` to convert generic classes into CSV format and back.
You have to give the properties of the CSV serialisable classes a `CSVColumn` attribute for them to be targeted for serialisation.
You can also pass a `CSVSerialiserOptions` object to the serialisation/deserialisation for more settings.If you dont want to use this statically typed serialisation and deserialisation, there is also a `DynamicCSV` class.
This is intended for times you dont have a class structure or just want a more "direct" way of making CSV files.
In it you can add and remove columns, rows, cells, etc at will.## Example
Class to serialise/deserialize:
```csharp
public class TestClass
{
[CSVColumn("Column1")]
public string Value { get; set; }
}
```
You can then use the serialiser and deserialiser as follows:
```csharp
var csvText = CSVSerialiser.Serialise(new List(){ new TestClass(){ Value = "abc" } });
```
Gives
```csv
Column1
abc
```## Example
Class to serialise/deserialize:
```csharp
public class TestClass2
{
[CSVColumn("Column1")]
public string Value { get; set; }
[CSVColumn("Column 2")]
public string Value2 { get; set; }
}
```
You can also make the CSV print more readably:
```csharp
var csvText = CSVSerialiser.Serialise(
new List(){
new TestClass2(){ Value = "asdafaseasasd", Value2 = "abc" }
}, new CSVSerialiserOptions(){ PrettyOutput = true });
```
Gives
```csv
Column1 ,Column 2
asdafaseasasd,abc
```## Example
An example of how to use the `DynamicCSV` object:
```csharp
var item = new DynamicCSV(new Dictionary>());
item.AddColumn("some-column");
item.Insert("some-column", 0, "abc");
item.Insert("some-column", 2, "123");
var csvText = CSVSerialiser.Serialise(item);
```
Gives the CSV output:
```csv
some-column
abc123
```