我怎么能够把某个特定单元的MD5或SHA1的字面打上,并将其放到谷歌Spreadsheet的另一间牢房?
是否有这样的公式:=ComputeMD5(A1)
或=ComputeSHA1(A1)
?
Or is it possible to write custom formula for this? How?
我怎么能够把某个特定单元的MD5或SHA1的字面打上,并将其放到谷歌Spreadsheet的另一间牢房?
是否有这样的公式:=ComputeMD5(A1)
或=ComputeSHA1(A1)
?
Or is it possible to write custom formula for this? How?
开放式<代码>Tools > 文本编辑 接着颁布以下法典:
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 is the SHA1 version of that code (very simple change)
function GetSHA1(input) {
var rawHash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, input);
var txtHash = ;
for (j = 0; j <rawHash.length; j++) {
var hashVal = rawHash[j];
if (hashVal < 0)
hashVal += 256;
if (hashVal.toString(16).length == 1)
txtHash += "0";
txtHash += hashVal.toString(16);
}
return txtHash;
}
Ok, got it,
Need to create custom function as explained in http://code.google.com/googleapps/appsscript/articles/custom_function.html
And then use the apis as explained in http://code.google.com/googleapps/appsscript/service_utilities.html
我需要交出完整的功能名称,以便我能够看到这一结果。
Following is the sample of the code that gave base 64 encoded hash of the text
function getBase64EncodedMD5(text)
{
return Utilities.base64Encode( Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, text));
}
这一解决办法与其他办法的区别是:
解决了上述解决办法中的一些问题,抵消了<代码>的产出。 Utilities.computeDigest (单位:128人,而不是256人)
它确定了一个问题,即通过在<条码>上打上<条码>,<>条码/代码>,在将其通过至<条码>公共事业之前,为不同投入制作同样的海面。
function MD5(input) {
var result = "";
var byteArray = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, JSON.stringify(input));
for (i=0; i < byteArray.length; i++) {
result += (byteArray[i] + 128).toString(16) + "-";
}
result = result.substring(result, result.length - 1); // remove trailing dash
return result;
}
to get hashes for a range of cells, add this next to gabhubert s function:
function RangeGetMD5Hash(input) {
if (input.map) { // Test whether input is an array.
return input.map(GetMD5Hash); // Recurse over array if so.
} else {
return GetMD5Hash(input)
}
}
以这种方式使用:
=RangeGetMD5Hash(A5:X25)
它的回报范围与源1相同,价值将缩小,并且与公式相距。
它把通用的单一价值功能推向广域转换方法(ref),而且其速度比每个电池的单独形式要快;其形式也为单一电池工作,因此可能值得以这种方式重写源功能。
以@gabhubert为基础,但利用阵列行动获得六dec代表
function sha(str){
return Utilities
.computeDigest(Utilities.DigestAlgorithm.SHA_1, str) // string to digested array of integers
.map(function(val) {return val<0? val+256 : val}) // correct the offset
.map(function(val) {return ("00" + val.toString(16)).slice(-2)}) // add padding and enconde
.join( ); // join in a single string
}
如果你想从一整段获得结果,你就可以这样做。 撰稿人。
function GetMD5Hash(value) {
var rawHash = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, value);
var txtHash = ;
for (j = 0; j <rawHash.length; j++) {
var hashVal = rawHash[j];
if (hashVal < 0)
hashVal += 256;
if (hashVal.toString(16).length == 1)
txtHash += "0";
txtHash += hashVal.toString(16);
}
return txtHash;
}
function straightToText() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var r = 1;
var n_rows = 9999;
var n_cols = 1;
var column = 1;
var sheet = ss[0].getRange(r, column, n_rows, ncols).getValues(); // get first sheet, a1:a9999
var results = [];
for (var i = 0; i < sheet.length; i++) {
var hashmd5= GetMD5Hash(sheet[i][0]);
results.push(hashmd5);
}
var dest_col = 3;
for (var j = 0; j < results.length; j++) {
var row = j+1;
ss[0].getRange(row, dest_col).setValue(results[j]); // write output to c1:c9999 as text
}
}
接着,从Run menu开始,只是简单地管理着ToText(ToText)的职能,以便你能够取得结果,并且把太多的电话引向功能错误。
我正在寻求一种能够提供较短结果的选择。 你们对此有何想法? 它只是回报4。 不幸的是,它使用一 s和 o,这可以分别混为L s和0s;右ont和帽子大为 matter。
function getShortMD5Hash(input) {
var rawHash = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, input);
var txtHash = ;
for (j = 0; j < 16; j += 8) {
hashVal = (rawHash[j] + rawHash[j+1] + rawHash[j+2] + rawHash[j+3]) ^ (rawHash[j+4] + rawHash[j+5] + rawHash[j+6] + rawHash[j+7])
if (hashVal < 0)
hashVal += 1024;
if (hashVal.toString(36).length == 1)
txtHash += "0";
txtHash += hashVal.toString(36);
}
return txtHash.toUpperCase();
}
我需要从一系列囚室里带一个洗衣,因此我这样认为:
function RangeSHA256(input)
{
return Array.isArray(input) ?
input.map(row => row.map(cell => SHA256(cell))) :
SHA256(input);
}
I m making a script that will populate a Google Sheet with info about our GA4 analytics properties. It starts by listing all our accounts, then looping through them and listing any GA4 properties in ...
I need an urgent help i have data as follows in a google sheet i need to add a year counter to the column d as follows using google apps script
I have a Google Spreadsheet with 3 columns that are either blank or have a value. I want to get the count of the number of rows that has A and either B or C populated. If I were writing a SQL query ...
If I create a Google apps script, can I hook it up to Google spreadsheet to run based on an event, or must I manually invoke it? I don t know if Google Sheets supports any events. For example: a ...
I am working with a small theatre company. Currently they have a list of people on paper with notes about their skills next to each one. I want to create a database / directory for them so that they ...
I ve seen; Accessing Google Spreadsheets with C# using Google Data API and http://code.google.com/apis/spreadsheets/data/2.0/developers_guide_dotnet.html#CreatingRows However i m still having ...
I have this code which is working, to load a Google Spreadsheet and load some data from it. If the spreadsheet in question is public, how do i modify the code to not require a username/password? $key=...
I ve got a pre-existing Google spreadsheet. Each month I update this document. I ve got a template workseet in the spreadseet that I d like to clone and then update. I d prefer to clone the ...