本帖最后由 LIUZHU 于 2024-3-18 19:49 编辑
试一下
- function 陪餐费统计表(){
- let s=Sheets.Item("陪餐缴费统计表").Range("a1").Value2;
- let sf=Sheets.Item("陪餐缴费统计表").Range("a19:a29").Value2.flat();
- let [year,month]=[s.match(/(\d+(?=年))/)[0],s.match(/(\d+(?=月))/)[0]];
- let end=new Date(year,month,0,8,0,0).getDate();
- let bt=[[],[],[]],wf=WorksheetFunction;
- let arr1=[],arr2=[];
- let m=1; //统计当星期数
- for (let i=1;i<=end;i++){
- let weekday=new Date(year,month-1,i,8,0,0).getDay();
- weekday=weekday==0?7:weekday;
- if (weekday==6 || weekday==7){
- if (i>=1 && weekday==6) m+=0.5; //增加半个星期
- if (i>=2 && weekday==7) m+=0.5; //增加半个星期
- continue;
- }
- let idate=new Date(year,month-1,i,8,0,0).getTime()/(24*3600*1000)+25569 //1970-1-1:25569
- bt[0].push(idate,null,null);
- bt[1].push(`星期${wf.Text(weekday,"[dbnum1]")}`,null,null);
- bt[2].push("早","中","晚");
- [0,1].forEach(x=>{ //教师陪餐统计
- let n=2*(m-1)+x;
- let k=bt[0].length-3;
- let temp=arr1[n]=arr1[n] || [];
- [temp[k],temp[k+1],temp[k+2]]=[3,5,5];
- });
- for (j=0;j<sf.length;j++){ //师傅就餐统计
- let temp=arr2[j]=arr2[j] || [];
- temp.push(3,5,sf[j].includes("赵")?null:5);
- }
- }
- [["B3:BR5",bt],["B6:BR17",arr1],["B19:BR29",arr2]].forEach(([rngstr,darr])=>{
- Range(rngstr).ClearContents();
- Range(rngstr).Cells.Item(1,1).Resize(darr.length,darr[darr.length-1].length).Value2=darr;
- });
- }
复制代码 |