• Stars
    star
    159
  • Rank 235,916 (Top 5 %)
  • Language
    C#
  • Created almost 10 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Very simple CSV-export tool for C#

CsvExport

A very simple and very fast CSV-export tool for C#.

.NET

Features

  1. Excel-compatible export (separator detected automatically, friendly-trimming rows and values for compatibility)
  2. Escapes commas, quotes, multiline text
  3. Exports dates in timezone-proof format
  4. Extremely easy to use
  5. NET Standard 2.0 library (compatible with both .NET Core and .NET Framework)
  6. 30 times faster than CsvHelper
  7. 4-times less memory usage

Benchmarks

Method Mean Error StdDev Gen0 Gen1 Allocated
😟 CsvHelper 1,300.38 us 32.043 us 1.756 us 17.5781 7.8125 114.25 KB
βœ… CsvExport_Manual 31.22 us 5.750 us 0.315 us 4.7607 0.2441 29.37 KB
βœ… CsvExport_Typed 52.68 us 1.453 us 0.080 us 4.7607 0.1221 29.46 KB

This benchmark is generating a 100-line CSV file with 4 columns. Check the "SpeedBenchmarks" code.

Usage examples:

Install via Nuget Install-Package CsvExport

For "manual" CSV ad-hoc generation use this:

var myExport = new CsvExport();

myExport.AddRow();
myExport["Region"] = "Los Angeles, USA";
myExport["Sales"] = 100000;
myExport["Date Opened"] = new DateTime(2003, 12, 31);

myExport.AddRow();
myExport["Region"] = "Canberra \"in\" Australia";
myExport["Sales"] = 50000;
myExport["Date Opened"] = new DateTime(2005, 1, 1, 9, 30, 0);

///ASP.NET MVC action example
return File(myExport.ExportToBytes(), "text/csv", "results.csv");

For generating CSV out of a typed List<T> of objects:

public class Foo
{
	public string Region { get; set; }
	public int Sales { get; set; }
	public DateTime DateOpened { get; set; }
}

var list = new List<Foo>
{
	new Foo { Region = "Los Angeles", Sales = 123321, DateOpened = DateTime.Now },
	new Foo { Region = "Canberra in Australia", Sales = 123321, DateOpened = DateTime.Now },
};

var myExport = new CsvExport();
myExport.AddRows(list);
string csv = myExport.Export();

Configuring is done via constructor parameters:

var myExport = new CsvExport(
	columnSeparator: ",",
	includeColumnSeparatorDefinitionPreamble: true, //Excel wants this in CSV files
	includeHeaderRow: true
);

Also, methods ExportToFile and ExportToBytes offer an optional encoding parameter.

License

The code is licensed under MIT License.

Sucessfully tested for years in production with our Jitbit Helpdesk Ticketing System

More Repositories

1

AspNetSaml

Very simple SAML 2.0 consumer module for ASP.NET/C#
C#
361
star
2

HtmlSanitizer

Fast JavaScript HTML Sanitizer, client-side (i.e. needs a browser, won't work in Node and other backend)
HTML
145
star
3

FastCache

7x-10x faster alternative to MemoryCache. A high-performance, lighweight (8KB dll) and thread-safe memory cache for .NET.
C#
132
star
4

MapDataReader

Super fast mapping DataReader to strongly typed object, Using AOT source generator.
C#
60
star
5

PropMapper

Object mapper for .NET. Flat and basic, but FAST.
C#
33
star
6

TabUtils

Multiple browser tabs communication, locking and synchronization
JavaScript
25
star
7

MurmurHash.net

C# .NET implementation of Murmur Hash
C#
18
star
8

SyslogCore

Simple (!) way to write to syslog aka /dev/log aka /var/log/syslog in .NET Core on Linux
C#
16
star
9

WinDefender

Invoke Windows Defender scan from C# .NET Core
C#
15
star
10

vs-unused-image-finder

Find unused images in Visual Studio ASP.NET projects
C#
10
star
11

JsonIgnoreProps

tiny helper class to exclude a property from Json Serialization
C#
9
star
12

Helpdesk-API

Jitbit Helpdesk API samples (python, c#, php, ruby, javascript)
C#
9
star
13

unzipnew

unzip only newer/updated files (by checking their hash) for Windows
C#
5
star
14

MediumNodeJs

Short script to publish a post to Medium
JavaScript
2
star
15

ResxTranslatorBot

Resx-Translator-Bot uses mymemory.translated.net API to automatically translate the .resx-files in your .NET and ASP.NET applications.
C#
2
star
16

HNRank

Read HN comments for any page while browsing the web. More info: https://jitbit.com/hacker-news-rank/
JavaScript
1
star
17

nanobox

extremely lightweight "lightbox"
JavaScript
1
star
18

s3cmdwin

tiny command line utility to store files in AWS S3 for Windows
C#
1
star
19

awssgip2c

JavaScript
1
star