Table of Contents

Class CsvHelper

Namespace
WeihanLi.Npoi
Assembly
WeihanLi.Npoi.dll

CsvHelper

public static class CsvHelper
Inheritance
CsvHelper
Inherited Members

Fields

CsvQuoteCharacter

CsvQuoteCharacter, " by default

public static char CsvQuoteCharacter

Field Value

char

CsvSeparatorCharacter

CsvSeparatorCharacter, ',' by default

public static char CsvSeparatorCharacter

Field Value

char

Methods

GetCsvLines<TEntity>(IEnumerable<TEntity>, CsvOptions?)

Get csv lines

public static IEnumerable<string> GetCsvLines<TEntity>(this IEnumerable<TEntity> entities, CsvOptions? csvOptions = null)

Parameters

entities IEnumerable<TEntity>

entities

csvOptions CsvOptions

csvOptions

Returns

IEnumerable<string>

csv lines

Type Parameters

TEntity

entity type

GetCsvText(DataTable?, bool)

Get csv text

public static string GetCsvText(this DataTable? dataTable, bool includeHeader = true)

Parameters

dataTable DataTable
includeHeader bool

Returns

string

GetCsvText(DataTable?, CsvOptions)

GetCsvText

public static string GetCsvText(this DataTable? dataTable, CsvOptions csvOptions)

Parameters

dataTable DataTable

dataTable

csvOptions CsvOptions

csvOptions

Returns

string

csv text

GetCsvText<TEntity>(IEnumerable<TEntity>, bool)

Get csv text

public static string GetCsvText<TEntity>(this IEnumerable<TEntity> entities, bool includeHeader = true)

Parameters

entities IEnumerable<TEntity>
includeHeader bool

Returns

string

Type Parameters

TEntity

GetCsvText<TEntity>(IEnumerable<TEntity>, CsvOptions)

Get csv text

public static string GetCsvText<TEntity>(this IEnumerable<TEntity> entities, CsvOptions csvOptions)

Parameters

entities IEnumerable<TEntity>
csvOptions CsvOptions

Returns

string

Type Parameters

TEntity

GetEntities<TEntity>(IEnumerable<string>, CsvOptions?)

public static IEnumerable<TEntity?> GetEntities<TEntity>(IEnumerable<string> csvLines, CsvOptions? csvOptions = null)

Parameters

csvLines IEnumerable<string>
csvOptions CsvOptions

Returns

IEnumerable<TEntity>

Type Parameters

TEntity

GetEntities<TEntity>(string, CsvOptions?)

public static IEnumerable<TEntity?> GetEntities<TEntity>(string csvText, CsvOptions? csvOptions = null)

Parameters

csvText string
csvOptions CsvOptions

Returns

IEnumerable<TEntity>

Type Parameters

TEntity

GetEntityList<TEntity>(IEnumerable<string>, CsvOptions?)

public static List<TEntity?> GetEntityList<TEntity>(IEnumerable<string> csvLines, CsvOptions? csvOptions = null)

Parameters

csvLines IEnumerable<string>
csvOptions CsvOptions

Returns

List<TEntity>

Type Parameters

TEntity

GetEntityList<TEntity>(string, CsvOptions?)

public static List<TEntity?> GetEntityList<TEntity>(string csvText, CsvOptions? csvOptions = null)

Parameters

csvText string
csvOptions CsvOptions

Returns

List<TEntity>

Type Parameters

TEntity

ParseLine(string)

public static IReadOnlyList<string> ParseLine(string line)

Parameters

line string

Returns

IReadOnlyList<string>

ParseLine(string, CsvOptions)

public static IReadOnlyList<string> ParseLine(string line, CsvOptions csvOptions)

Parameters

line string
csvOptions CsvOptions

Returns

IReadOnlyList<string>

ToCsvBytes(DataTable)

to csv bytes

public static byte[] ToCsvBytes(this DataTable dt)

Parameters

dt DataTable

Returns

byte[]

ToCsvBytes(DataTable, bool)

to csv bytes

public static byte[] ToCsvBytes(this DataTable dataTable, bool includeHeader)

Parameters

dataTable DataTable
includeHeader bool

Returns

byte[]

ToCsvBytes(DataTable, CsvOptions)

to csv bytes

public static byte[] ToCsvBytes(this DataTable dataTable, CsvOptions csvOptions)

Parameters

dataTable DataTable
csvOptions CsvOptions

Returns

byte[]

ToCsvBytes<TEntity>(IEnumerable<TEntity>)

to csv bytes

public static byte[] ToCsvBytes<TEntity>(this IEnumerable<TEntity> entities)

Parameters

entities IEnumerable<TEntity>

Returns

byte[]

Type Parameters

TEntity

ToCsvBytes<TEntity>(IEnumerable<TEntity>, bool)

to csv bytes

public static byte[] ToCsvBytes<TEntity>(this IEnumerable<TEntity> entities, bool includeHeader)

Parameters

entities IEnumerable<TEntity>
includeHeader bool

Returns

byte[]

Type Parameters

TEntity

ToCsvBytes<TEntity>(IEnumerable<TEntity>, CsvOptions)

to csv bytes

public static byte[] ToCsvBytes<TEntity>(this IEnumerable<TEntity> entities, CsvOptions csvOptions)

Parameters

entities IEnumerable<TEntity>
csvOptions CsvOptions

Returns

byte[]

Type Parameters

TEntity

ToCsvFile(DataTable, string)

save to csv file

public static bool ToCsvFile(this DataTable dt, string filePath)

Parameters

dt DataTable
filePath string

Returns

bool

ToCsvFile(DataTable, string, bool)

save to csv file

public static bool ToCsvFile(this DataTable dataTable, string filePath, bool includeHeader)

Parameters

dataTable DataTable
filePath string
includeHeader bool

Returns

bool

ToCsvFile(DataTable, string, CsvOptions)

save to csv file

public static bool ToCsvFile(this DataTable dataTable, string filePath, CsvOptions csvOptions)

Parameters

dataTable DataTable
filePath string
csvOptions CsvOptions

Returns

bool

ToCsvFileAsync<TEntity>(IEnumerable<TEntity>, string, CsvOptions?)

public static Task<bool> ToCsvFileAsync<TEntity>(this IEnumerable<TEntity> entities, string filePath, CsvOptions? csvOptions = null)

Parameters

entities IEnumerable<TEntity>
filePath string
csvOptions CsvOptions

Returns

Task<bool>

Type Parameters

TEntity

ToCsvFile<TEntity>(IEnumerable<TEntity>, string)

save to csv file

public static bool ToCsvFile<TEntity>(this IEnumerable<TEntity> entities, string filePath)

Parameters

entities IEnumerable<TEntity>
filePath string

Returns

bool

Type Parameters

TEntity

ToCsvFile<TEntity>(IEnumerable<TEntity>, string, bool)

save to csv file

public static bool ToCsvFile<TEntity>(this IEnumerable<TEntity> entities, string filePath, bool includeHeader)

Parameters

entities IEnumerable<TEntity>
filePath string
includeHeader bool

Returns

bool

Type Parameters

TEntity

ToCsvFile<TEntity>(IEnumerable<TEntity>, string, CsvOptions)

public static bool ToCsvFile<TEntity>(this IEnumerable<TEntity> entities, string filePath, CsvOptions csvOptions)

Parameters

entities IEnumerable<TEntity>
filePath string
csvOptions CsvOptions

Returns

bool

Type Parameters

TEntity

ToDataTable(byte[])

convert csv file data to dataTable

public static DataTable ToDataTable(byte[] csvBytes)

Parameters

csvBytes byte[]

csv bytes

Returns

DataTable

ToDataTable(byte[], CsvOptions)

public static DataTable ToDataTable(byte[] csvBytes, CsvOptions csvOptions)

Parameters

csvBytes byte[]
csvOptions CsvOptions

Returns

DataTable

ToDataTable(Stream)

convert csv stream data to dataTable

public static DataTable ToDataTable(Stream stream)

Parameters

stream Stream

stream

Returns

DataTable

ToDataTable(Stream, CsvOptions)

convert csv stream data to dataTable

public static DataTable ToDataTable(Stream stream, CsvOptions csvOptions)

Parameters

stream Stream

stream

csvOptions CsvOptions

csvOptions

Returns

DataTable

ToDataTable(string)

convert csv file data to dataTable

public static DataTable ToDataTable(string filePath)

Parameters

filePath string

csv file path

Returns

DataTable

ToEntities<TEntity>(byte[], CsvOptions?)

public static IEnumerable<TEntity?> ToEntities<TEntity>(byte[] csvBytes, CsvOptions? csvOptions = null)

Parameters

csvBytes byte[]
csvOptions CsvOptions

Returns

IEnumerable<TEntity>

Type Parameters

TEntity

ToEntities<TEntity>(Stream, CsvOptions?)

public static IEnumerable<TEntity?> ToEntities<TEntity>(Stream csvStream, CsvOptions? csvOptions = null)

Parameters

csvStream Stream
csvOptions CsvOptions

Returns

IEnumerable<TEntity>

Type Parameters

TEntity

ToEntities<TEntity>(string, CsvOptions?)

convert csv file data to entities

public static IEnumerable<TEntity?> ToEntities<TEntity>(string filePath, CsvOptions? csvOptions = null)

Parameters

filePath string

csv file path

csvOptions CsvOptions

csvOptions

Returns

IEnumerable<TEntity>

Type Parameters

TEntity

ToEntityList<TEntity>(byte[])

convert csv byte data to entity list

public static List<TEntity?> ToEntityList<TEntity>(byte[] csvBytes)

Parameters

csvBytes byte[]

csv bytes

Returns

List<TEntity>

Type Parameters

TEntity

ToEntityList<TEntity>(byte[], CsvOptions)

convert csv byte data to entity list

public static List<TEntity?> ToEntityList<TEntity>(byte[] csvBytes, CsvOptions csvOptions)

Parameters

csvBytes byte[]

csv bytes

csvOptions CsvOptions

csvOptions

Returns

List<TEntity>

Type Parameters

TEntity

ToEntityList<TEntity>(Stream)

convert csv stream data to entity list

public static List<TEntity?> ToEntityList<TEntity>(Stream csvStream)

Parameters

csvStream Stream

csv Stream

Returns

List<TEntity>

Type Parameters

TEntity

ToEntityList<TEntity>(Stream, CsvOptions)

public static List<TEntity?> ToEntityList<TEntity>(Stream csvStream, CsvOptions csvOptions)

Parameters

csvStream Stream
csvOptions CsvOptions

Returns

List<TEntity>

Type Parameters

TEntity

ToEntityList<TEntity>(string)

convert csv file data to entity list

public static List<TEntity?> ToEntityList<TEntity>(string filePath)

Parameters

filePath string

csv file path

Returns

List<TEntity>

Type Parameters

TEntity

ToEntityList<TEntity>(string, CsvOptions)

convert csv file data to entity list

public static List<TEntity?> ToEntityList<TEntity>(string filePath, CsvOptions csvOptions)

Parameters

filePath string

csv file path

csvOptions CsvOptions

csvOptions

Returns

List<TEntity>

Type Parameters

TEntity