/// <summary> /// Convert single column data by header name. /// </summary> public static IEnumerable <T> ConvertColumnEnumerator <T>(string csvContent, string headerName, char cellSeparator = CSVDataHelper.CommaCharacter, bool supportCellMultiline = true) { if (!TryInitConvertColumnByName <T>(csvContent, headerName, cellSeparator, supportCellMultiline, out var csvTableReader)) { yield break; } var index = Array.IndexOf(csvTableReader.Headers[0].Cells, headerName); foreach (var record in csvTableReader.Records) { yield return(FieldConverter.Convert <T>(record.Cells[index])); } }
/// <summary> /// Convert single column data by header index. /// </summary> public static List <T> ConvertColumn <T>(string csvContent, int headerIndex = 0, char cellSeparator = CSVDataHelper.CommaCharacter, bool supportCellMultiline = true) { if (headerIndex < 0) { headerIndex = 0; } if (!TryInitConvertColumnByIndex <T>(csvContent, headerIndex, cellSeparator, supportCellMultiline, out var csvTableReader)) { return(null); } List <T> dataList = new List <T>(csvTableReader.RecordRow); foreach (var record in csvTableReader.Records) { dataList.Add(headerIndex < record.Cells.Length ? FieldConverter.Convert <T>(record.Cells[headerIndex]) : default);
/// <summary> /// Convert single column data by header name. /// </summary> public static List <T> ConvertColumn <T>(string csvContent, string headerName, char cellSeparator = CSVDataHelper.CommaCharacter, bool supportCellMultiline = true) { if (!TryInitConvertColumnByName <T>(csvContent, headerName, cellSeparator, supportCellMultiline, out var csvTableReader)) { return(null); } var index = Array.IndexOf(csvTableReader.Headers[0].Cells, headerName); List <T> dataList = new List <T>(csvTableReader.RecordRow); foreach (var record in csvTableReader.Records) { dataList.Add(FieldConverter.Convert <T>(record.Cells[index])); } return(dataList); }