CodingYang

vuePress-theme-reco Rackar    2018 - 2024
CodingYang CodingYang

Choose mode

  • dark
  • auto
  • light
首页
类别
  • 技术
  • 个人
  • 思考
  • 儿童
标签
时间线
联系
  • 关于
  • RSS订阅 (opens new window)
  • GitHub (opens new window)
  • 简书 (opens new window)
  • CSDN (opens new window)
  • WeChat (opens new window)
GitHub (opens new window)
author-avatar

Rackar

67

文章

44

标签

首页
类别
  • 技术
  • 个人
  • 思考
  • 儿童
标签
时间线
联系
  • 关于
  • RSS订阅 (opens new window)
  • GitHub (opens new window)
  • 简书 (opens new window)
  • CSDN (opens new window)
  • WeChat (opens new window)
GitHub (opens new window)
  • Excel 比对两列数据的异同

    • 命令
      • js 查重

Excel 比对两列数据的异同

vuePress-theme-reco Rackar    2018 - 2024

Excel 比对两列数据的异同


Rackar 2021-09-15 Excel Windows

两列数据对比找差异,还是 Excel 最简便。

1631694882197.png

# 命令

=VLOOKUP(A1,B:B,1,0)
1

这是查 A 列中的重复值的公式,如 C 列示意。

还可以交换一下顺序查 B 列,如 D 列示意。

# js 查重

为方便自定义还是上代码。Node.js 对比两个文本文件中各行的异同。这笨拙的循环查重算法要是被面试官看到估计会直接被毙。管他呢又不是不能用。

const fs = require("fs");

function diff(urlOne, urlTwo) {
  const s1 = fs.readFileSync(urlOne, "utf-8");
  const s2 = fs.readFileSync(urlTwo, "utf-8");
  const arr1 = s1.replace(/\r\n/g, "\n").split("\n");
  const arr2 = s2.replace(/\r\n/g, "\n").split("\n");
  const resultUnique1 = [];
  const resultUnique2 = [];
  const sameValue = [];
  for (const name1 of arr1) {
    if (arr2.includes(name1)) {
      sameValue.push(name1);
    } else {
      resultUnique1.push(name1);
    }
  }

  for (const name2 of arr2) {
    if (!sameValue.includes(name2)) {
      resultUnique2.push(name2);
    }
  }

  const msg1 = `${urlOne}中唯一数据有${
    resultUnique1.length
  }条,分别为:\r\n${resultUnique1.join("\r\n")}`;
  const msg2 = `\r\n------------------------\r\n${urlTwo}中唯一数据有${
    resultUnique2.length
  }条,分别为:\r\n${resultUnique2.join("\r\n")}`;
  const msg3 = `\r\n------------------------\r\n 重复值有${
    sameValue.length
  }条,分别为:\r\n${sameValue.join("\r\n")}`;
  const msg = msg1 + msg2 + msg3;
  console.log(msg);
}

diff("./diff/A.txt", "./diff/B.txt");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
参与编辑此文章 (opens new window)
更新于: 9/15/2021, 4:56:29 PM