public static string Encode(CsvData csvData, Dictionary <int, FieldFormatOption> formatOptions, string separator) { CsvEncoder encoder = new CsvEncoder(); encoder.FormatOptions = formatOptions; encoder.Separator = separator; return(encoder.EncodeCsvData(csvData)); }
private string EncodeCsvData(CsvData csvData) { StringBuilder text = new StringBuilder(); if (csvData.HasHeader) { text.AppendLine(EncodeRecord(csvData.Header)); } foreach (CsvRecord record in csvData.Records) { text.AppendLine(EncodeRecord(record)); } return(text.ToString()); }
public static CsvData Decode(string text, bool hasHeader) { if (text == null) { throw new ArgumentNullException("text"); } bool success; Parser parser = new Parser(); CsvData csvData = parser.ParseCsvData(new TextInput(text), out success); if (success) { if (hasHeader) { csvData.Header = csvData.Records[0]; csvData.Records.RemoveAt(0); } return(csvData); } else { throw new Exception("There are syntax errors in the csv text."); } }
public static string Encode(CsvData csvData) { return(Encode(csvData, null)); }
/// <summary> /// Encode CsvData with Format Options /// </summary> /// <param name="csvData"></param> /// <param name="formatOptions">FieldFormatOption dict that use 0 based field index as key</param> /// <returns></returns> public static string Encode(CsvData csvData, Dictionary <int, FieldFormatOption> formatOptions) { return(Encode(csvData, formatOptions, ",")); }