本帖最后由 boyuanoffice 于 2024-3-21 10:38 编辑
本来想取个巧, 奈何数据太大,那就用笨方法了:
- =LET(dt,E2:H12,up,E1:H1,lft,A2:D12,VSTACK({"标题1","标题2","标题3","月份","科目","金额"},
- HSTACK(
- TOCOL(IF(dt,CHOOSECOLS(lft,1),NA()),2),
- TOCOL(IF(dt,CHOOSECOLS(lft,2),NA()),2),
- TOCOL(IF(dt,CHOOSECOLS(lft,3),NA()),2),
- TOCOL(IF(dt,CHOOSECOLS(lft,4),NA()),2),
- TOCOL(IF(dt,up,NA()),2),
- TOCOL(dt,1)
- )))
复制代码
咋觉着中间部分能用循环来做. 试了一下, 果然可以:
- =LET(dt,E2:H12,up,E1:H1,lft,A2:D12,VSTACK({"标题1","标题2","标题3","月份","科目","金额"},
- HSTACK(
- DROP(REDUCE("",SEQUENCE(4),LAMBDA(x,y,HSTACK(x,TOCOL(IF(dt,CHOOSECOLS(lft,y),NA()),2)))),,1),
- TOCOL(IF(dt,up,NA()),2),
- TOCOL(dt,1)
- )))
复制代码
|