将字符串转换为Google Spreadsheet中的公式

加斯顿·巴

我已经阅读了十多个小时,并尝试了不同的选择,但都没有成功。

我有这个字符串(这实际上是由其他公式生成的字符串)

QUERY({IMPORTRANGE(A1;$D$1);IMPORTRANGE(A2;$D$1);IMPORTRANGE(A3;$D$1);IMPORTRANGE(A4;$D$1)};"select Col13, sum(Col1), sum(Col2), sum(Col3), sum(Col4), sum(Col5), sum(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12) group by Col13";0)

我希望将其理解为公式。因此,例如,我尝试此功能:

function doConvert(formula) {
  // Strip leading "=" if there
  if (formula.charAt(0) === '=') formula = formula.substring(1);
  return eval(formula);
}

但是我得到:

错误/语法错误:属性ID后面缺少“:”。

(用英文写成:“:”(在属性ID后丢失)。

任何其他解决方案都很好。

玩家0

添加=到您生成的字符串,然后尝试这样:

function onEdit() { 
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet_Name_Here');  
var src = sheet.getRange("A1");              // The cell which holds the formula
var str = src.getValue(); 
var cell = sheet.getRange("C5");             // The cell where you want the results to be in
cell.setFormula(str);              
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章