学习15楼的代码,有所获,改写了下,同样达到效果
- function test1(){
- const obj={0:[10,12], 1:[1,3], 2:[4,6], 3:[7,9], 4:[10,12]} //季度和月份的关系
- let [year,month]=["i1","i2"].map(x=>Sheets.Item("指定时间段").Range(x).Value2); //年、月
- let ye=year-(month<=3), [st,ed]=obj[Math.ceil(month/3)-1];
- const arr=Sheets.Item("资料源").Range("a1").CurrentRegion.Value2;
- let res=arr.reduce((res,[a,b,,c,d,e])=>(a==ye && b>=st && b<=ed?res.push([e,c,d]):null,res),[["代码","借方金额","贷方金额"]]);
- Sheets.Item("季度表").Range("Y5").Resize(res.length,res[0].length).Value2=res;
- }
复制代码 |