|
你的数据不多,速度快慢能分得出来吗?
- function 取重复项并汇总() {
- const st = Date.now();
- const db = Range('B1').CurrentRegion();
- const map = new Map();
- for (let j = 0; j < db[1].length; j += 3) {
- for (let i = 2; i < db.length; i++) {
- const [id, name, amount] = [0, 1, 2].map(n => db[i][j + n]);
- const key = `${String(id).padStart(3, 0)}|${name}`;
- if (id) {
- if (!map.has(key)) map.set(key, [0, 0]);
- map.get(key)[0]++;
- map.get(key)[1] += amount;
- }
- }
- }
- const res = [...map].map(([k, v]) => [...k.split('|'), ...v]).sort((a, b) => a[0] - b[0]);
- res.unshift(['学号', '名字', '重复次数', '额汇总']);
- with (Range('AI1').Resize(res.length, res[0].length)) {
- CurrentRegion.ClearContents();
- Value2 = res;
- }
- alert(`统计完成,耗时【${(Date.now() - st) / 1000}】秒~`);
- }
复制代码
|
评分
-
1
查看全部评分
-
|