本帖最后由 tmplinshi 于 2024-3-17 18:35 编辑
- =LET(
- src, A2:B26,
- cat, H1:J11,
- loop, LAMBDA(fn, [idx], [groupData], [out],
- LET(
- idx, idx + 1,
- a, INDEX(src, idx, 1),
- b, LET(x, INDEX(src, idx, 2), TEXTBEFORE(x, "、",,,, x)),
- isCatExist, IF(a <> "", 0, ISNUMBER(MATCH(b, groupData, 0))),
- i, MAX(IF(cat = b, SEQUENCE(, COLUMNS(cat)))),
- c, INDEX(cat, 1, i),
- py, SWITCH(c, "水果", "SG", "办公", "BG", "五金", "WJ"),
- n, COUNT(SEARCH(c & "*", out)) * 2 ^ (py = "WJ") + 1,
- result, IF(i, c & py & n & IF(py = "WJ", "~" & py & n + 1, ""), ""),
- out, IF(idx = 1, result, VSTACK(out, IF(isCatExist, "", result))),
- groupData, IF(a <> "", VSTACK(b), VSTACK(groupData, b)),
- IF(idx < ROWS(src), fn(fn, idx, groupData, out), out)
- )
- ),
- loop(loop)
- )
复制代码
(注:原文件“办公”列下面缺少了“钢笔”) |