|
| 1 | +namespace MiniExcelLibs |
| 2 | +{ |
| 3 | + using MiniExcelLibs.Utils; |
| 4 | + using System; |
| 5 | + using System.Collections.Generic; |
| 6 | + using System.Data; |
| 7 | + using System.IO; |
| 8 | + using System.Linq; |
| 9 | + |
| 10 | + public class MiniExcelDataReader : IDataReader |
| 11 | + { |
| 12 | + private readonly IEnumerator<IDictionary<string, object>> _source; |
| 13 | + private readonly int _fieldCount; |
| 14 | + private readonly List<string> _keys; |
| 15 | + private readonly Stream _stream; |
| 16 | + private bool _isFirst = true; |
| 17 | + |
| 18 | + internal MiniExcelDataReader(Stream stream, bool useHeaderRow = false, string sheetName = null, ExcelType excelType = ExcelType.UNKNOWN, string startCell = "A1", IConfiguration configuration = null) |
| 19 | + { |
| 20 | + _stream = stream; |
| 21 | + _source = MiniExcel.Query(_stream, useHeaderRow, sheetName, excelType, startCell, configuration).Cast<IDictionary<string, object>>().GetEnumerator(); |
| 22 | + var isNext = _source.MoveNext(); |
| 23 | + if (isNext) |
| 24 | + { |
| 25 | + _keys = _source.Current.Keys.ToList(); |
| 26 | + _fieldCount = _keys.Count; |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + public void Dispose() |
| 31 | + { |
| 32 | + _stream.Dispose(); |
| 33 | + } |
| 34 | + |
| 35 | + public object GetValue(int i) |
| 36 | + { |
| 37 | + return _source.Current[_keys[i]]; |
| 38 | + } |
| 39 | + |
| 40 | + public int FieldCount |
| 41 | + { |
| 42 | + get { return _fieldCount; } |
| 43 | + } |
| 44 | + |
| 45 | + public bool Read() |
| 46 | + { |
| 47 | + if (_isFirst) |
| 48 | + { |
| 49 | + _isFirst = false; |
| 50 | + return true; |
| 51 | + } |
| 52 | + return _source.MoveNext(); |
| 53 | + } |
| 54 | + |
| 55 | + public string GetName(int i) |
| 56 | + { |
| 57 | + return _keys[i]; |
| 58 | + } |
| 59 | + |
| 60 | + public int GetOrdinal(string name) |
| 61 | + { |
| 62 | + var i = _keys.IndexOf(name); |
| 63 | + return _keys.IndexOf(name); |
| 64 | + } |
| 65 | + |
| 66 | + public void Close() |
| 67 | + { |
| 68 | + throw new NotImplementedException(); |
| 69 | + } |
| 70 | + |
| 71 | + public int Depth => throw new NotImplementedException(); |
| 72 | + |
| 73 | + public bool IsClosed => throw new NotImplementedException(); |
| 74 | + |
| 75 | + public int RecordsAffected => throw new NotImplementedException(); |
| 76 | + |
| 77 | + public object this[string name] => throw new NotImplementedException(); |
| 78 | + |
| 79 | + public object this[int i] => throw new NotImplementedException(); |
| 80 | + |
| 81 | + public DataTable GetSchemaTable() |
| 82 | + { |
| 83 | + throw new NotImplementedException(); |
| 84 | + } |
| 85 | + |
| 86 | + public bool NextResult() |
| 87 | + { |
| 88 | + throw new NotImplementedException(); |
| 89 | + } |
| 90 | + |
| 91 | + public bool GetBoolean(int i) |
| 92 | + { |
| 93 | + throw new NotImplementedException(); |
| 94 | + } |
| 95 | + |
| 96 | + public byte GetByte(int i) |
| 97 | + { |
| 98 | + throw new NotImplementedException(); |
| 99 | + } |
| 100 | + |
| 101 | + public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) |
| 102 | + { |
| 103 | + throw new NotImplementedException(); |
| 104 | + } |
| 105 | + |
| 106 | + public char GetChar(int i) |
| 107 | + { |
| 108 | + throw new NotImplementedException(); |
| 109 | + } |
| 110 | + |
| 111 | + public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length) |
| 112 | + { |
| 113 | + throw new NotImplementedException(); |
| 114 | + } |
| 115 | + |
| 116 | + public IDataReader GetData(int i) |
| 117 | + { |
| 118 | + throw new NotImplementedException(); |
| 119 | + } |
| 120 | + |
| 121 | + public string GetDataTypeName(int i) |
| 122 | + { |
| 123 | + throw new NotImplementedException(); |
| 124 | + } |
| 125 | + |
| 126 | + public DateTime GetDateTime(int i) |
| 127 | + { |
| 128 | + throw new NotImplementedException(); |
| 129 | + } |
| 130 | + |
| 131 | + public decimal GetDecimal(int i) |
| 132 | + { |
| 133 | + throw new NotImplementedException(); |
| 134 | + } |
| 135 | + |
| 136 | + public double GetDouble(int i) |
| 137 | + { |
| 138 | + throw new NotImplementedException(); |
| 139 | + } |
| 140 | + |
| 141 | + public Type GetFieldType(int i) |
| 142 | + { |
| 143 | + throw new NotImplementedException(); |
| 144 | + } |
| 145 | + |
| 146 | + public float GetFloat(int i) |
| 147 | + { |
| 148 | + throw new NotImplementedException(); |
| 149 | + } |
| 150 | + |
| 151 | + public Guid GetGuid(int i) |
| 152 | + { |
| 153 | + throw new NotImplementedException(); |
| 154 | + } |
| 155 | + |
| 156 | + public short GetInt16(int i) |
| 157 | + { |
| 158 | + throw new NotImplementedException(); |
| 159 | + } |
| 160 | + |
| 161 | + public int GetInt32(int i) |
| 162 | + { |
| 163 | + throw new NotImplementedException(); |
| 164 | + } |
| 165 | + |
| 166 | + public long GetInt64(int i) |
| 167 | + { |
| 168 | + throw new NotImplementedException(); |
| 169 | + } |
| 170 | + |
| 171 | + public string GetString(int i) |
| 172 | + { |
| 173 | + throw new NotImplementedException(); |
| 174 | + } |
| 175 | + |
| 176 | + public int GetValues(object[] values) |
| 177 | + { |
| 178 | + throw new NotImplementedException(); |
| 179 | + } |
| 180 | + |
| 181 | + public bool IsDBNull(int i) |
| 182 | + { |
| 183 | + throw new NotImplementedException(); |
| 184 | + } |
| 185 | + } |
| 186 | +} |
0 commit comments