【特性】cfg excel格式支持以map的key作标题头,但必须配合orientation=c使用
parent
ae63bd883b
commit
f82df5d68d
|
|
@ -287,9 +287,46 @@ namespace Luban.Job.Cfg.DataCreators
|
|||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
|
||||
private bool TryCreateColumnStream(Sheet.NamedRow x, Sheet.Title title, out ExcelStream stream)
|
||||
{
|
||||
var cells = new List<Sheet.Cell>();
|
||||
for (int i = title.FromIndex; i <= title.ToIndex; i++)
|
||||
{
|
||||
foreach (var row in x.Rows)
|
||||
{
|
||||
if (row.Count > i)
|
||||
{
|
||||
var value = row[i].Value;
|
||||
if (!(value == null || (value is string s && string.IsNullOrEmpty(s))))
|
||||
{
|
||||
cells.Add(row[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cells.Count > 0)
|
||||
{
|
||||
stream = new ExcelStream(cells, 0, cells.Count - 1, "", false);
|
||||
return true;
|
||||
}
|
||||
stream = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public DType Accept(TMap type, Sheet.NamedRow x, bool multirow, bool nullable)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
var map = new Dictionary<DType, DType>();
|
||||
foreach (var (key, keyTitle) in x.Titles)
|
||||
{
|
||||
if (TryCreateColumnStream(x, keyTitle, out var stream))
|
||||
{
|
||||
var keyData = type.KeyType.Apply(StringDataCreator.Ins, key);
|
||||
var valueData = type.ValueType.Apply(ExcelDataCreator.Ins, null, stream, DefAssembly.LocalAssebmly);
|
||||
map.Add(keyData, valueData);
|
||||
}
|
||||
}
|
||||
return new DMap(type, map);
|
||||
}
|
||||
|
||||
public DType Accept(TVector2 type, Sheet.NamedRow x, bool multirow, bool nullable)
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
|
|||
}
|
||||
else
|
||||
{
|
||||
List<DefField> notMultiRowFields = bean.Bean.HierarchyFields.Select(f => (DefField)f).Where(f => !f.IsMultiRow).ToList();
|
||||
List<DefField> notMultiRowFields = bean.Bean.HierarchyFields.Select(f => (DefField)f).Where(f => !f.IsMultiRow && f.IsRowOrient).ToList();
|
||||
List<List<Cell>> recordRows = null;
|
||||
foreach (var row in rows)
|
||||
{
|
||||
|
|
@ -262,7 +262,8 @@ namespace Luban.Job.Cfg.DataSources.Excel
|
|||
{
|
||||
if (!IsBlankColumn(Rows, i))
|
||||
{
|
||||
yield return new ExcelStream(Rows.Select(r => r[i]).ToList(), 0, Rows.Count - 1, sep, false);
|
||||
var cells = Rows.Where(r => r.Count > i).Select(r => r[i]).Where(v => !(v.Value == null || (v.Value is string s && string.IsNullOrEmpty(s)))).ToList();
|
||||
yield return new ExcelStream(cells, 0, cells.Count - 1, sep, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -661,6 +662,10 @@ namespace Luban.Job.Cfg.DataSources.Excel
|
|||
{
|
||||
foreach (List<Cell> row in rows)
|
||||
{
|
||||
if (column >= row.Count)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var v = row[column].Value;
|
||||
if (v != null && !(v is string s && string.IsNullOrEmpty(s)))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace Luban.Job.Cfg.RawDefs
|
|||
|
||||
public string DefaultValue { get; set; } = "";
|
||||
|
||||
public bool IsRowOrient { get; set; } = false;
|
||||
public bool IsRowOrient { get; set; } = true;
|
||||
|
||||
public List<string> Groups { get; set; } = new List<string>();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue