|
JSA代码,参考下
- function 分类汇总(){
- let regex=new RegExp(Sheets.Item("分包人").Range("a1").CurrentRegion.Value2.slice(1).map(([x])=>x).join("|"));
- let obj=Sheets.Item("表一").Range("a1").CurrentRegion.Value2.slice(2).reduce((dic,x)=>{
- if (!regex.test(x[1])) return dic;
- x[2]=x[1].match(regex)[0];
- let temp=dic[x[2]]=dic[x[2]] || [[,x[2],0,,,,,]];
- temp.splice(temp.length-1,0,x.slice(1))
- temp[temp.length-1][2]+=x[3];
- return dic;
- },{});
- let res=Object.values(obj).flat();
- Sheets.Item("分类汇总表").Activate();
- Range("2:" + Math.max(2,ActiveSheet.UsedRange.Rows.Count)).ClearContents();
- Range("b2").Resize(res.length,res[0].length).Value2=res;
- }
复制代码 |
|