|
JSA代码,都写麻木了,想不到VBA要写多少
- function 数据转换(){
- Sheets.Item("转换后数据").Activate();
- const arr=Sheets.Item("源数据").Range("a1").CurrentRegion.Value2;
- const bt1=arr[1].reduce((bt1,x,i)=>(bt1[x]=i,bt1),{});
- const bt2=Range("a1").CurrentRegion.Value2[0].reduce((bt2,x,i)=>(bt2[x]=i,bt2),{});
- const mbarr=new Array(Object.keys(bt2).length).fill(null);
- let obj={},dic={},k=0;
- arr.slice(2).forEach(x=>{
- let key=x[bt1.学号] + x[bt1.课程名称];
- let temp=obj[key]=obj[key] || [...mbarr];
- if (x[bt1.考试类型]=="正考"){
- ["学号","姓名","班级","课程名称","姓名"].forEach(i=>temp[bt2[i]]=x[bt1[i]]);
- [temp[bt2.正考学年], temp[bt2.正考学期]]=[x[bt1.成绩学年学期].slice(0,9), x[bt1.成绩学年学期].slice(-1)];
- [temp[bt2.总评成绩], temp[bt2.再补考最高成绩]]=[x[bt1.综合成绩], "=MAX(RC[19]:RC[24])"];
- [temp[bt2.序号], temp[bt2.录入成绩教师姓名], temp[bt2.录入补考成绩]]=[++k, x[bt1.操作人], "=RC[-18]"];
- let marr=x[bt1.成绩分项描述].match(/(?<=:)\d+/g);
- [temp[bt2.平时成绩], temp[bt2.期末成绩]]=marr!=null?[marr[0],marr[1]]:[,,];
- }else if (x[bt1.考试类型].includes("补考")){
- if (temp[bt2.学号]=="2113010108"){
- let a;
- }
- let ikey=key + "补考";
- dic[ikey]=(dic[ikey] || 0) + 1;
- if (dic[ikey]==1){
- temp[bt2.补考成绩]=x[bt1.综合成绩];
- }else{
- let n=bt2[`再补考${dic[ikey]-1}成绩`];
- temp[n]=x[bt1.综合成绩];
- }
- }
- });
- let res=Object.values(obj);
- Range("a2").Resize(res.length,res[0].length).FormulaR1C1=res;
- ThisWorkbook.Save();
- }
复制代码 |
|