|
这表弄得太繁琐了,用JS先写一点,用WPS2022打开使用
- //统计班级排名、全校排名
- function statistical_ranking() {
- let sht1 = Sheets('总表')
- let arr = sht1.Range('A1').CurrentRegion.Value2;
- arr.shift();
- //按第二列班级汇总
- const classes = {};
- summary_column(arr, 1, (e) => {
- for (let i in e) {
- let arr = e[i].map(i => [i[0], i[16]]); //提取考号、总分成绩
- alike_ranking(classes, arr) //统计各班排名
- }
- });
- const school = {};
- let brr = arr.map(i => [i[0], i[16]]);
- alike_ranking(school, brr); //统计全校排名
- //写入班级排名、全校排名
- let rng = sht1.Range('R2').Resize(arr.length, 2);
- rng.Value2 = arr.map(i => [classes[i[0]], school[i[0]]]);
- write_summary()
- alert('统计完成');
- }
- //写入质量分析表
- function write_summary() {
- let sht1 = Sheets('总表')
- let sht2 = Sheets('质量分析')
- let arr = sht1.Range('A1').CurrentRegion.Value2;
- arr.shift();
- //班级平均分
- let brr = [];
- summary_column(arr, 1, (e) => {
- for (let i in e) {
- let arr = e[i]
- let x = 0 //班级总分
- arr.forEach(i => x += i[16])
- let y = Math.floor((x / arr.length) * 100) / 100; //班级平均分
- brr.push([i, y])
- }
- })
- const clss = {};
- alike_ranking(clss, brr)
- let data = brr.map(i => [i[0], i[1], clss[i[0]]])
- sht2.Range('A8:C11').Value2 = data.sort()
- }
- //按某列汇总为对象{'班级': [二维数组]}
- function summary_column(arr = [], col = 0, callback = Function) {
- const obj = {}
- arr.forEach(i => {
- let a = i[col]
- if (obj[a]) return obj[a].push(i);
- obj[a] = [i]
- })
- callback(obj)
- return obj
- }
- //解决并列排名问题,arr[考号, 分数]
- function alike_ranking(obj = {}, arr = []) {
- arr = arr.sort((x, y) => y[1] - x[1]) //降序排序
- const brr = {}
- let a = 1
- arr.forEach(i => {
- let x = i[0],
- y = i[1]
- if (brr[y]) {
- obj[x] = brr[y]
- } else {
- obj[x] = a
- brr[y] = a
- a++
- }
- })
- }
复制代码 |
|