Google 电子表格中单元格文本的哈希值 [英] Hash of a cell text in Google Spreadsheet

查看:28
本文介绍了Google 电子表格中单元格文本的哈希值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算特定单元格中文本的 MD5 或 SHA1 哈希值并将其设置为 Google 电子表格中的另一个单元格?

How can I compute a MD5 or SHA1 hash of text in a specific cell and set it to another cell in Google Spreadsheet?

是否有=ComputeMD5(A1)=ComputeSHA1(A1)这样的公式?

或者是否可以为此编写自定义公式?怎么样?

Or is it possible to write custom formula for this? How?

推荐答案

打开 Tools >脚本编辑器然后粘贴以下代码:

Open Tools > Script Editor then paste the following code:

function MD5 (input) {
  var rawHash = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, input);
  var txtHash = '';
  for (i = 0; i < rawHash.length; i++) {
    var hashVal = rawHash[i];
    if (hashVal < 0) {
      hashVal += 256;
    }
    if (hashVal.toString(16).length == 1) {
      txtHash += '0';
    }
    txtHash += hashVal.toString(16);
  }
  return txtHash;
}

之后保存脚本,然后在引用单元格时在电子表格中使用 MD5() 函数.

Save the script after that and then use the MD5() function in your spreadsheet while referencing a cell.

此脚本基于 Utilities.computeDigest() 函数.

这篇关于Google 电子表格中单元格文本的哈希值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆