JS宏使用fast-diff库标记单元格的不同之处
创作者俱乐部成员
今天看到论坛里问https://bbs.wps.cn/topic/54564如何标记单元格不同之处
试了一下fast-diff库,可以在JS宏里使用
有了库,代码就比较简单,只是把结果连起来,染色,加删除线这些
🔔 | function tt() { const a = Range('A1:C10').Value2 const b = Range('E1:G10').Value2 for (let i = 0; i < a.length; i++) { for (let j = 0; j < a[0].length; j++) { if (typeof a[i][j] !== 'string') continue const t = fd(a[i][j], b[i][j]) Cells(i + 1, j + 9).Value2 = t.map(x=>x[1]).join('') let x = 1 for (const k of t) { if (k[0] < 0) { Cells(i + 1, j + 9).Characters(x, k[1].length).Font.Color = 0xff Cells(i + 1, j + 9).Characters(x, k[1].length).Font.Strikethrough = true } if (k[0] > 0) { Cells(i + 1, j + 9).Characters(x, k[1].length).Font.Color = 0xff } x += k[1].length } } } } |
链接: https://pan.baidu.com/s/1sur0FNh8Ah-OTwrKfjtmlQ?pwd=ywp9 提取码: ywp9
注意:需要在宏编辑器里,工具,选项,编译,去掉两个禁止全局的选项
感兴趣的小伙伴可以试一下,不知道是否严谨,不过增删改都被标记出来了,还算能用
创作者俱乐部成员