parent
3b17094618
commit
59276dd503
|
|
@ -289,9 +289,8 @@ namespace Luban.Job.Cfg.DataCreators
|
||||||
}
|
}
|
||||||
else if (row.Rows != null)
|
else if (row.Rows != null)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
var s = row.AsMultiRowConcatStream(sep);
|
||||||
//var s = row.AsMultiRowStream(sep);
|
return type.Apply(ExcelStreamDataCreator.Ins, s);
|
||||||
//return new DArray(type, ReadList(type.ElementType, s));
|
|
||||||
}
|
}
|
||||||
else if (row.Fields != null)
|
else if (row.Fields != null)
|
||||||
{
|
{
|
||||||
|
|
@ -332,12 +331,11 @@ namespace Luban.Job.Cfg.DataCreators
|
||||||
|
|
||||||
return new DBean(originBean, originBean, CreateBeanFields(originBean, sheet, row));
|
return new DBean(originBean, originBean, CreateBeanFields(originBean, sheet, row));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (row.Elements != null)
|
else if (row.Elements != null)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
var s = row.AsMultiRowConcatElements(sep);
|
||||||
|
return type.Apply(ExcelStreamDataCreator.Ins, s);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -345,9 +343,6 @@ namespace Luban.Job.Cfg.DataCreators
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<DType> ReadList(TType type, ExcelStream stream)
|
public List<DType> ReadList(TType type, ExcelStream stream)
|
||||||
{
|
{
|
||||||
var datas = new List<DType>();
|
var datas = new List<DType>();
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,58 @@ namespace Luban.Job.Cfg.DataSources.Excel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExcelStream(List<List<Cell>> rows, int fromIndex, int toIndex, string sep, string overrideDefault)
|
||||||
|
{
|
||||||
|
_overrideDefault = overrideDefault;
|
||||||
|
this._datas = new List<Cell>();
|
||||||
|
if (string.IsNullOrWhiteSpace(sep))
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(overrideDefault))
|
||||||
|
{
|
||||||
|
foreach (var row in rows)
|
||||||
|
{
|
||||||
|
for (int i = fromIndex; i <= toIndex; i++)
|
||||||
|
{
|
||||||
|
this._datas.Add(row[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new NotSupportedException("concated multi rows don't support 'default' ");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var row in rows)
|
||||||
|
{
|
||||||
|
for (int i = fromIndex; i <= toIndex; i++)
|
||||||
|
{
|
||||||
|
var cell = row[i];
|
||||||
|
object d = cell.Value;
|
||||||
|
if (!IsSkip(d))
|
||||||
|
{
|
||||||
|
if (d is string s)
|
||||||
|
{
|
||||||
|
this._datas.AddRange(DataUtil.SplitStringByAnySepChar(s, sep).Select(x => new Cell(cell.Row, cell.Column, x)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this._datas.Add(cell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!string.IsNullOrEmpty(_overrideDefault))
|
||||||
|
{
|
||||||
|
this._datas.Add(new Cell(cell.Row, cell.Column, _overrideDefault));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._curIndex = 0;
|
||||||
|
this._toIndex = this._datas.Count - 1;
|
||||||
|
}
|
||||||
|
|
||||||
public string First => _datas[_curIndex].Value?.ToString();
|
public string First => _datas[_curIndex].Value?.ToString();
|
||||||
|
|
||||||
public string LastReadDataInfo => _datas[Math.Min(LastReadIndex, _datas.Count - 1)].ToString();
|
public string LastReadDataInfo => _datas[Math.Min(LastReadIndex, _datas.Count - 1)].ToString();
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,12 @@ namespace Luban.Job.Cfg.DataSources.Excel
|
||||||
|
|
||||||
string titleName = attrs[0];
|
string titleName = attrs[0];
|
||||||
var tags = new Dictionary<string, string>();
|
var tags = new Dictionary<string, string>();
|
||||||
|
// * 开头的表示是多行
|
||||||
|
if (titleName.StartsWith('*'))
|
||||||
|
{
|
||||||
|
titleName = titleName.Substring(1);
|
||||||
|
tags.Add("multi_rows", "1");
|
||||||
|
}
|
||||||
foreach (var attrPair in attrs.Skip(1))
|
foreach (var attrPair in attrs.Skip(1))
|
||||||
{
|
{
|
||||||
var pairs = attrPair.Split('=');
|
var pairs = attrPair.Split('=');
|
||||||
|
|
|
||||||
|
|
@ -118,24 +118,19 @@ namespace Luban.Job.Cfg.DataSources.Excel
|
||||||
|
|
||||||
public IEnumerable<ExcelStream> AsMultiRowStream(string sep)
|
public IEnumerable<ExcelStream> AsMultiRowStream(string sep)
|
||||||
{
|
{
|
||||||
//if (Titles.TryGetValue(name, out var title))
|
|
||||||
//{
|
|
||||||
// if (isRowOrient)
|
|
||||||
// {
|
|
||||||
// var totalCells = Rows.SelectMany(r => r.GetRange(title.FromIndex, title.ToIndex - title.FromIndex + 1))
|
|
||||||
// .Where(c => c.Value != null && !(c.Value is string s && string.IsNullOrWhiteSpace(s))).ToList();
|
|
||||||
// return new ExcelStream(totalCells, 0, totalCells.Count - 1, sep, false);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// throw new NotSupportedException($"bean类型多行数据不支持纵向填写");
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
// throw new Exception($"单元薄 缺失 列:{name},请检查是否写错或者遗漏");
|
|
||||||
//}
|
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExcelStream AsMultiRowConcatStream(string sep)
|
||||||
|
{
|
||||||
|
sep = string.IsNullOrEmpty(sep) ? SelfTitle.Sep : sep;
|
||||||
|
return new ExcelStream(Rows, SelfTitle.FromIndex, SelfTitle.ToIndex, sep, SelfTitle.Default);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExcelStream AsMultiRowConcatElements(string sep)
|
||||||
|
{
|
||||||
|
sep = string.IsNullOrEmpty(sep) ? SelfTitle.Sep : sep;
|
||||||
|
return new ExcelStream(Elements.Select(e => e.Row).ToList(), SelfTitle.FromIndex, SelfTitle.ToIndex, sep, SelfTitle.Default);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue