|
- function test(){
- let arr = Sheets("信息表").Range("a1").CurrentRegion.Value2
- let data = arr.slice(1)
- let dic = {} //字典
- let bt = ["班级","学科","总分","平均分","大于等于60分人数","大于等于80分人数"]//表头
- data.forEach (row => {//行循环
- let col = arr[0].slice(3) //截取学科列
- col.forEach((c,i) =>{//学科循环
- let key = row[1] + c // 以班级加学科为字典的key
- if (! dic[key]){
- dic[key] = Array(6).fill(null)
- dic[key][0] = row[1]
- dic[key][1] = c
- dic[key][2] = row [ i + 3]//直接取学科对应的分
- if (row [ i + 3] >= 60) dic[key][4]++
- if (row [ i + 3] >= 80) dic[key][5]++
- dic[key][3] ++ //平均分:暂时存放总人数, + 1
- }else{
- dic[key][0] = row[1]
- dic[key][1] = c
- dic[key][2] = dic[key][2] + row [ i + 3]//总分加再次出现的新分
- if (row [ i + 3] >= 60) dic[key][4]++
- if (row [ i + 3] >= 80) dic[key][5]++
- dic[key][3] ++ //平均分:暂时存放总人数, + 1
- }
- })
-
- })
- let res = Object.values( dic )
- res.forEach((v,i) => res[i][3] = (v[2]/v[3]).toFixed(2))
- res.unshift(bt)
- Sheets("计算表").Range("j1").CurrentRegion.ClearContents()
- Sheets("计算表").Range("j1").Resize(res.length,res[0].length).Value2 = res
- }
复制代码
按班求总分.rar
(45.17 KB, 下载次数: 8)
没检查,不知结果和要求的是否一样
|
|