| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Globalization; |
| | | 4 | | using System.IO; |
| | | 5 | | using System.Linq; |
| | | 6 | | using System.Reflection; |
| | | 7 | | using System.Text; |
| | | 8 | | using WinSolutions.Sveta.Server.Data.DataModel.Entities; |
| | | 9 | | using WinSolutions.Sveta.Server.Data.DataLoading.Records; |
| | | 10 | | using ExcelDataReader; |
| | | 11 | | using System.Data; |
| | | 12 | | |
| | | 13 | | namespace WinSolutions.Sveta.Server.Data.DataLoading.Parsers |
| | | 14 | | { |
| | | 15 | | public class CsvParser<T> : BaseParser<T> where T : BaseRecord, new() |
| | | 16 | | { |
| | | 17 | | protected override DataTable ReadLines(Stream stream) |
| | 0 | 18 | | { |
| | 0 | 19 | | System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); |
| | 0 | 20 | | var readerConfig = new ExcelReaderConfiguration() |
| | 0 | 21 | | { |
| | 0 | 22 | | AutodetectSeparators = new char[] { ';', '\t', '|' }, |
| | 0 | 23 | | AnalyzeInitialCsvRows = 0 |
| | 0 | 24 | | }; |
| | | 25 | | |
| | 0 | 26 | | using (var reader = ExcelReaderFactory.CreateCsvReader(stream, readerConfig)) |
| | 0 | 27 | | { |
| | 0 | 28 | | var conf = new ExcelDataSetConfiguration |
| | 0 | 29 | | { |
| | 0 | 30 | | ConfigureDataTable = _ => new ExcelDataTableConfiguration |
| | 0 | 31 | | { |
| | 0 | 32 | | UseHeaderRow = true, |
| | 0 | 33 | | ReadHeaderRow = (rowReader) => |
| | 0 | 34 | | { |
| | 0 | 35 | | rowReader.Read(); // пропускаем описание шаблона |
| | 0 | 36 | | rowReader.Read(); // пропускаем русские колонки |
| | 0 | 37 | | } |
| | 0 | 38 | | } |
| | 0 | 39 | | }; |
| | | 40 | | |
| | 0 | 41 | | return reader.AsDataSet(conf).Tables[0]; |
| | | 42 | | } |
| | 0 | 43 | | } |
| | | 44 | | } |
| | | 45 | | } |