Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google sheets 如何将数字转换为字母_Google Sheets - Fatal编程技术网

Google sheets 如何将数字转换为字母

Google sheets 如何将数字转换为字母,google-sheets,Google Sheets,我有一张显示物品成本的表。我想做的不是显示数字,而是使用以下黑马:B=1,L=2,A=3,C=4,K=5,H=6,7=O,8=R,9=S和E=0。我该如何在谷歌表单中的脚本中输入这些内容,比如说,单元格h9是它输入的项目总成本的总和,而不是数字 可能有许多方法可以计算所需的值。将其视为一种方法。 功能so5715442701(){ var ss=SpreadsheetApp.getActiveSpreadsheet(); var sheetname=“57154427”; var sheet=

我有一张显示物品成本的表。我想做的不是显示数字,而是使用以下黑马:B=1,L=2,A=3,C=4,K=5,H=6,7=O,8=R,9=S和E=0。我该如何在谷歌表单中的脚本中输入这些内容,比如说,单元格h9是它输入的项目总成本的总和,而不是数字


可能有许多方法可以计算所需的值。将其视为一种方法。


功能so5715442701(){
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheetname=“57154427”;
var sheet=ss.getSheetByName(sheetname);
//在javascript key:value数组中查找给定值的键的代码
Object.prototype.getKey=函数(值){
for(此字段中的var键){
if(此[键]==值){
返回键;
}
}
返回null;
};
//一个键:BLACKHORSE的值数组
var blackhorse={
B:1,
L:2,
A:3,
C:4,
K:5,
H:6,
O:7,
R:8,
S:9,
E:0
};
//从单元格中获取成本值
var costprice=sheet.getRange(“C15”).getValue();
//将数字转换为字符串
var cost=costprice.toString();//转换为字符串
//Logger.log(“调试:成本=“+cost+”,长度=“+cost.length”);
//设置一个变量以累积结果
var costtotal=“”;
//循环遍历成本值中的字符
对于(变量i=0;i

信用
-

-

那么,如果总成本是30美元,你期望得到什么?fwiwan是一个没有重复字母的词。十个字母的等值线表示数字1-10。维基百科说,PATHFINDER、Dumbwater和BLACKHORSE等10个字母的等值线图通常被销售人员用于零售价格通常协商的产品,如二手车、珠宝或古董。在PATHFINDER密码中,P=1,A=2,等等。因此,如果一件售价为1200美元的物品带有神秘的字母FRR,销售人员将知道该物品的原始成本是500美元,并且能够更好地进行谈判。@AAA如果一件物品的成本是30美元,那么“黑马”值将是AE。
function so5715442701() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheetname = "57154427";
  var sheet = ss.getSheetByName(sheetname);

  // code to find the key for a given value in a javascript key:value array
  Object.prototype.getKey = function(value){
    for(var key in this){
    if(this[key] == value){
      return key;
    }
  }
    return null;
  };

 // a key:value array for BLACKHORSE
  var blackhorse = { 
    B : 1,
    L : 2,
    A : 3,
    C : 4,
    K : 5,
    H : 6,
    O : 7,
    R : 8,
    S : 9,
    E : 0
  };

  // get the cost value from a cell    
  var costprice = sheet.getRange("C15").getValue();

  // convert the number to a string
  var cost = costprice.toString(); // convert to string
  //Logger.log("DEBUG: cost = "+cost+", length = "+cost.length);

  // set a variable to accumulate the results
  var costtotal="";

  // loop through the characters in the cost value
  for (var i = 0; i < cost.length; i++) {
    var letter = cost.charAt(i);
    var costkey = blackhorse.getKey(letter);
    var costtotal = costtotal+costkey  
  }

  //Logger.log("DEBUG: cost = "+cost+", Blackhourse cost = "+costtotal); 
  sheet.getRange("D15").setValue(costtotal);

}