From 27e9bd2d1fd58d8a33fec4033d783ebf3fa8be1e Mon Sep 17 00:00:00 2001 From: walon Date: Thu, 29 Jul 2021 18:35:56 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E8=AF=BB?= =?UTF-8?q?=E5=8F=96excel=E6=95=B0=E6=8D=AE=E5=87=BA=E9=94=99=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=89=93=E5=8D=B0=E5=87=BA=E6=AD=A3=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E5=87=BA=E9=94=99=E4=BD=8D=E7=BD=AE=EF=BC=88=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E6=9C=89=E5=8F=AF=E8=83=BD=E5=BE=80=E5=90=8E=E5=81=8F=E7=A7=BB?= =?UTF-8?q?=E4=B8=80=E4=BD=8D=EF=BC=8C=E7=BB=99=E5=87=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E4=BD=8D=E7=BD=AE=E4=BF=A1=E6=81=AF=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/DataCreators/ExcelDataCreator.cs | 2 +- .../DataCreators/ExcelNamedRowDataCreator.cs | 2 +- .../DataCreators/MultiRowExcelDataCreator.cs | 4 ++-- .../Source/DataSources/Excel/ExcelStream.cs | 18 ++++++++++++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/DataCreators/ExcelDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/ExcelDataCreator.cs index e36cee0..3caa585 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/ExcelDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/ExcelDataCreator.cs @@ -343,7 +343,7 @@ namespace Luban.Job.Cfg.DataCreators } catch (Exception e) { - var dce = new DataCreateException(e, stream.CurrentExcelPosition); + var dce = new DataCreateException(e, stream.LastReadDataInfo); dce.Push(bean, f); throw dce; } diff --git a/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs index a92999f..be81748 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs @@ -187,7 +187,7 @@ namespace Luban.Job.Cfg.DataCreators } catch (Exception e) { - var dce = new DataCreateException(e, stream.CurrentExcelPosition); + var dce = new DataCreateException(e, stream.LastReadDataInfo); dce.Push(bean, f); throw dce; } diff --git a/src/Luban.Job.Cfg/Source/DataCreators/MultiRowExcelDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/MultiRowExcelDataCreator.cs index bb581e9..9b8211d 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/MultiRowExcelDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/MultiRowExcelDataCreator.cs @@ -98,7 +98,7 @@ namespace Luban.Job.Cfg.DataCreators } catch (Exception e) { - var dce = new DataCreateException(e, stream.CurrentExcelPosition); + var dce = new DataCreateException(e, stream.LastReadDataInfo); throw dce; } } @@ -133,7 +133,7 @@ namespace Luban.Job.Cfg.DataCreators } catch (Exception e) { - var dce = new DataCreateException(e, stream.CurrentExcelPosition); + var dce = new DataCreateException(e, stream.LastReadDataInfo); throw dce; } } diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelStream.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelStream.cs index 504f086..94a51a8 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelStream.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelStream.cs @@ -6,6 +6,11 @@ using System.Text; namespace Luban.Job.Cfg.DataSources.Excel { + class DataNotEnoughException : System.Exception + { + + } + class ExcelStream { @@ -80,7 +85,9 @@ namespace Luban.Job.Cfg.DataSources.Excel public string First => _datas[_curIndex].Value?.ToString(); - public string CurrentExcelPosition => _datas[Math.Min(_curIndex, _datas.Count - 1)].ToString(); + public string LastReadDataInfo => _datas[Math.Min(LastReadIndex, _datas.Count - 1)].ToString(); + + private int LastReadIndex { get; set; } public int IncludeNullAndEmptySize => _toIndex - _curIndex + 1; @@ -106,9 +113,11 @@ namespace Luban.Job.Cfg.DataSources.Excel data = _datas[_curIndex++].Value; if (!IsSkip(data)) { + LastReadIndex = _curIndex - 1; return true; } } + LastReadIndex = _curIndex - 1; return false; } @@ -127,7 +136,7 @@ namespace Luban.Job.Cfg.DataSources.Excel private object ReadMayNull() { - return _curIndex <= _toIndex ? _datas[_curIndex++].Value : null; + return _curIndex <= _toIndex ? _datas[LastReadIndex = _curIndex++].Value : null; } //public object Read(bool nullable) @@ -142,9 +151,11 @@ namespace Luban.Job.Cfg.DataSources.Excel var data = _datas[_curIndex++]; if (!IsSkip(data.Value)) { + LastReadIndex = _curIndex - 1; return data; } } + LastReadIndex = _curIndex - 1; throw new Exception($"cell:{_datas[_curIndex - 1]} 缺少数据"); } @@ -155,9 +166,11 @@ namespace Luban.Job.Cfg.DataSources.Excel var data = _datas[_curIndex++]; if (!IsSkip(data.Value)) { + LastReadIndex = _curIndex - 1; return data.Value; } } + LastReadIndex = _curIndex - 1; throw new Exception($"cell:{_datas[_curIndex - 1]} 缺少数据"); } @@ -180,6 +193,7 @@ namespace Luban.Job.Cfg.DataSources.Excel { if (value == END_OF_LIST) { + LastReadIndex = _curIndex - 1; return true; } else