diff --git a/src/MiniExcel/Csv/CsvConfiguration.cs b/src/MiniExcel/Csv/CsvConfiguration.cs index b49c9769b92fe41ef7a94e1258e901e87e33c87e..9e3890347b8e47949064e9a06baf7f057098be0f 100644 --- a/src/MiniExcel/Csv/CsvConfiguration.cs +++ b/src/MiniExcel/Csv/CsvConfiguration.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Text; @@ -9,7 +9,8 @@ public class CsvConfiguration : Configuration private static Encoding _defaultEncoding = new UTF8Encoding(true); public char Seperator { get; set; } = ','; - public string NewLine { get; set; } = "\r\n"; + public string NewLine { get; set; } = "\r\n"; + public Func SplitFn { get; set; } public Func StreamReaderFunc { get; set; } = (stream) => new StreamReader(stream, _defaultEncoding); public Func StreamWriterFunc { get; set; } = (stream) => new StreamWriter(stream, _defaultEncoding); diff --git a/src/MiniExcel/Csv/CsvReader.cs b/src/MiniExcel/Csv/CsvReader.cs index 50d8eb3554b7488822590d616f58fb60d05af638..01616ada37559113e7c2fe9f4f4b3e3dda6e70e4 100644 --- a/src/MiniExcel/Csv/CsvReader.cs +++ b/src/MiniExcel/Csv/CsvReader.cs @@ -1,4 +1,4 @@ -using MiniExcelLibs.OpenXml; +using MiniExcelLibs.OpenXml; using MiniExcelLibs.Utils; using System; using System.Collections.Generic; @@ -73,9 +73,16 @@ public IEnumerable> Query(bool useHeaderRow, string private string[] Split(string row) { - return Regex.Split(row, $"[\t{_config.Seperator}](?=(?:[^\"]|\"[^\"]*\")*$)") - .Select(s => Regex.Replace(s.Replace("\"\"", "\""), "^\"|\"$", "")).ToArray(); - //this code from S.O : https://stackoverflow.com/a/11365961/9131476 + if (_config.SplitFn != null) + { + return _config.SplitFn(row); + } + else + { + return Regex.Split(row, $"[\t{_config.Seperator}](?=(?:[^\"]|\"[^\"]*\")*$)") + .Select(s => Regex.Replace(s.Replace("\"\"", "\""), "^\"|\"$", "")).ToArray(); + //this code from S.O : https://stackoverflow.com/a/11365961/9131476 + } } public Task>> QueryAsync(bool UseHeaderRow, string sheetName, string startCell,CancellationToken cancellationToken = default(CancellationToken))