【修复】读取excel数据出错时,打印出正确的出错位置(之前有可能往后偏移一位,给出错误的位置信息)
parent
df722abb4a
commit
27e9bd2d1f
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue