|
JSA代码,供参考
- function 汇总(){
- let bt=Range("a1").CurrentRegion.Value2[0];
- Workbooks.Open(`${ThisWorkbook.Path}\\源文件.xls`);
- let arr=Range("a1").CurrentRegion.Value2;
- ActiveWorkbook.Close(false);
- bt=[...new Set([...bt,...arr[0]])]; //更新表头
- let res=arr.slice(1).reduce((res,x)=>{
- let temp=arr[0].reduce((temp,y,i)=>(temp[bt.indexOf(y)]=x[i],temp),[]);
- return (res.push(temp),res);
- },[]);
- let rng=Range("a"+ Rows.Count).End(xlUp).Offset(1,0);
- rng.Resize(res.length,bt.length).Value2=res;
- Range("a1").Resize(1,bt.length).Value2=bt;
- }
复制代码 |
|