|
JSA代码
- function 汇总工作簿(){
- let fname=Dir(`${ThisWorkbook.Path}\\*.xls*`,8);
- let obj={"表头":["科目名称","期初余额借方","期初余额贷方","本期发生借方","本期发生贷方","期末余额借方","期末余额贷方"]};
- while(fname!=""){
- if (fname!=ThisWorkbook.Name){
- Workbooks.Open(`${ThisWorkbook.Path}\\${fname}`);
- Range("a1").CurrentRegion.Value2.slice(1).forEach(x=>{
- if (x[2]==null) return;
- let temp=obj[x[2]]=obj[x[2]] || [x[2],...new Array(obj.表头.length-1).fill(0)];
- temp.forEach((y,i)=>i>0?temp[i]+=x[i+2]:null);
-
- });
- ActiveWorkbook.Close(false);
- }
- fname=Dir();
- }
- Cells.ClearContents();
- let res=Object.values(obj);
- Range("a1").Resize(res.length,res[0].length).Value2=res;
- }
复制代码 |
|