【问题标题】:How to decode cloudflare email in Google sheets如何在 Google 表格中解码 cloudflare 电子邮件
【发布时间】:2022-11-12 12:13:07
【问题描述】:

我刚刚开始使用 Google Apps 脚本,在这里我正在尝试创建一个脚本来帮助我解码 Cloudflare 电子邮件。

我有以下 Javascript 代码,我已将其与我的其他代码融合以从 A 列获取值,并在转换后将它们放置在 B 列中。

我的代码抛出错误TypeError: sheetS.getRange(...).cfDecodeEmail is not a function

我有的:

function Decode() {

var sss = SpreadsheetApp.openById("1fDXv1L1YmXzbUXJbzGE6suc5HWToHlUuO-zBzVZDcX0");
var sheetS = sss.getSheetByName("Guide");
var AG1val = sheetS.getRange('A1:A').getValues(); // 


function cfDecodeEmail(encodedString) {
    var email = "", r = parseInt(encodedString.substr(0, 2), 16), n, i;
    for (n = 2; encodedString.length - n; n += 2){
        i = parseInt(encodedString.substr(n, 2), 16) ^ r;
        email += String.fromCharCode(i);
    }
    return email;
}

sheetS.getRange("B1:B").cfDecodeEmail(AG1val); // decode to B1:B
}

这是“未触及的”Javascript 代码,它有意做我想做的事情,除了我试图在 Appscript 中做它。

function cfDecodeEmail(encodedString) {
    var email = "", r = parseInt(encodedString.substr(0, 2), 16), n, i;
    for (n = 2; encodedString.length - n; n += 2){
        i = parseInt(encodedString.substr(n, 2), 16) ^ r;
        email += String.fromCharCode(i);
    }
    return email;
}

console.log(cfDecodeEmail("543931142127353935313e352e7a373b39")); // usage

谢谢。

【问题讨论】:

    标签: javascript google-apps-script google-sheets


    【解决方案1】:

    AG1val 是一个二维数组(参见:https://developers.google.com/apps-script/reference/spreadsheet/range#getvalues),您似乎正试图将它作为字符串传递给函数。

    您应该首先遍历该数组,通过 cfDecodeEMail 函数传递该数组的每个元素,然后将这些值写入 B1:B 范围。

    类似于下面的东西,做了一个快速测试,这似乎有效:

    function decode() {
        var sss = SpreadsheetApp.openById("1fDXv1L1YmXzbUXJbzGE6suc5HWToHlUuO-zBzVZDcX0");
        var sheetS = sss.getSheetByName("Guide");
        var AG1val = sheetS.getRange('A1:A').getValues(); // 
      
      function cfDecodeEmail(encodedString) {
          var email = "", r = parseInt(encodedString.substr(0, 2), 16), n, i;
          for (n = 2; encodedString.length - n; n += 2){
              i = parseInt(encodedString.substr(n, 2), 16) ^ r;
              email += String.fromCharCode(i);
          }
          return email;
      }
      
      let results = AG1val.map( (row) =>{ //loop through each row
          let cellValue = row[0]; //since there is only one column, get it by the first index (0)
          if(cellValue !== ''){ //pass the value to the function if cell contains a value
            return [cfDecodeEmail(cellValue)]; //return it in an array to contain the two-dimensional array structure
          } else{
            return ['']; //otherwise return an empty string
          }
      })
      
      sheetS.getRange("B1:B").setValues(results) //call the setValues function to write back to the sheet
      
    }
    

    【讨论】:

    • 试图执行解码,但已被删除。
    • 当我将 cfDecodeEmail() 放在变量之上时,效果很好!非常感谢!
    猜你喜欢
    • 2014-09-14
    • 1970-01-01
    • 2017-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-25
    • 2015-03-10
    相关资源
    最近更新 更多