将字符串转换为 Google 电子表格中的公式

Gas*_* BA 5 google-sheets google-apps-script google-sheets-query importrange google-sheets-formula

我\xc2\xb4d 花了 10 多个小时阅读并尝试不同的选项,但没有成功。

\n

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

\n
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)\n
Run Code Online (Sandbox Code Playgroud)\n

我希望它被理解为一个公式。\n例如我尝试这个函数:

\n
function doConvert(formula) {\n  // Strip leading "=" if there\n  if (formula.charAt(0) === '=') formula = formula.substring(1);\n  return eval(formula);\n}\n
Run Code Online (Sandbox Code Playgroud)\n

但我得到:

\n
\n

错误/语法错误:Falta ":" detr\xc3\xa1s del ID de propiedad。

\n

(在英语中,属性 ID 后面缺少“:”。

\n
\n

任何其他解决方案都会很棒。

\n

pla*_*er0 1

添加=到生成的字符串并尝试如下:

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);              
}
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

9248 次

最近记录:

5 年,10 月 前