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

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

问题描述

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

是否有像 = ComputeMD5(A1) = ComputeSHA1(A1)



或者是否有可能为此编写自定义公式?如何?

解决方案

打开工具>脚本编辑器,然后粘贴下面的代码:
$ b

  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 ()函数。



该脚本基于 Utilities.computeDigest()函数。


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

Is there a formula like =ComputeMD5(A1) or =ComputeSHA1(A1)?

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

解决方案

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;
}

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

This script is based on Utilities.computeDigest() function.

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

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