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