- // file
- let
- Source = Table.FirstValue(Excel.CurrentWorkbook(){[Name="表1"]}[Content])
- in
- Source
- // output
- let
- Source = Excel.Workbook(File.Contents(file), null, true){[Item="源表",Kind="Sheet"]}[Data],
- rows = Table.ToRows(Source)&{{""}},
- fx = (x)=>let slist=List.Alternate(x, 1, 1, 1),
- sdate=slist{3}{0},
- repl= List.ReplaceRange(slist, 3, 1, {List.ReplaceRange(slist{3}, 0, 1, {"值"})})
- in repl&{{"日期", sdate}},
- acc = List.Accumulate(
- rows,
- {null, null, {}, {}},
- (s,c)=>if s{0}=null and c{0}<>null
- then {c{0}, c{0}, { List.Skip(c)}, s{3}&
- { let lists=List.Split(List.Zip(s{2}), 8)
- in List.Transform(
- lists,
- each Table.PromoteHeaders(
- Table.FromColumns(
- fx(_)
- )
- )
- )
- }
- }
- else {c{0}, s{1}, s{2}&{List.Skip(c)}, s{3}}
- ){3},
- tbl = Table.Combine(List.Combine(acc)),
- filter = Table.SelectRows(tbl, each ([姓名] <> null)),
- result = Table.FillDown(filter, {"日期"})
- in
- result
复制代码 可以试一下这个
|